开发者

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

开发者 https://www.devze.com 2023-02-18 22:09 出处:网络
Here is the code I\'m using right now. $(window).load(function () { $(\'.answer\').hide(); }); $(\'.question\').click(function () {

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

精彩评论

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

关注公众号