jQuery单击标签内的div

时间:2014-11-06 08:48:33

标签: jquery html

我的HTML

<ul class="hotels-list clearfix">
     <li class="hotels-list-item clearfix">
         <a href="">
              <div class="btn-forward forward"></div>
              <div class="btn-back back"></div>
         </a>
      </li>
</ul>

有没有办法点击div标记内的a而无需点击父a代码?

我尝试使用代码bolow但它不起作用

$back = $(this).find('a.back'),
$forward = $(this).find('a.forward');

$back.click(function (e) {
                    e.stopPropagation();
                    e.preventDefault();
                    return gotoPage(currentPage - 1);
                });

                $forward.click(function (e) {
                    e.stopPropagation();
                    e.preventDefault();
                    return gotoPage(currentPage + 1);
                });

2 个答案:

答案 0 :(得分:1)

您的选择器错误,请使用

$back = $(this).find('a .back'),
$forward = $(this).find('a .forward');

答案 1 :(得分:1)

<ul class="hotels-list clearfix">
     <li class="hotels-list-item clearfix">
              <div class="btn-forward forward"></div>
              <div class="btn-back back"></div>
      </li>
</ul>

$back = $(this).find('.back'),
$forward = $(this).find('.forward');

$back.click(function (e) {
     e.stopPropagation();
     e.preventDefault();
     return gotoPage(currentPage - 1);
});

$forward.click(function (e) {
     e.stopPropagation();
     e.preventDefault();
     return gotoPage(currentPage + 1);
});

这是所有评论的总结:)