开发者

How can I select only the anchors within a div by id in jQuery?

Here is the code I'm using right now.

$(window).load(function () {
  $('.answer').hide();

});
$('.question').click(function () {
    var currentId = $(this).attr('id');
  $("#a"+currentId.substr(1)).fadeToggle("fast", func开发者_运维百科tion () {
  });
});+
$('#show_hide').click(function () {
  $(".answer").fadeToggle("fast", function () {
  });
});

The problem is that this code will be triggered if the user clicks anywhere on the same line as the link, and not just on the link itself. Help?


$(".question a")

You can use the selector part of Jquery quite creatively. Searches all elements with class question and then selects all the a tags inside of it

If you want id, then switch to hash

$("#question a")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜