Reputation: 87
I have a html code like this:
<div class="pagination">
<ul>
<li class="prev"><span>←</span></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li class="next"><a href="javascript::void(0)">→</a></li>
</ul>
</div><!-- .pagination -->
When I add click event for li tag, I want to click li tag don't have span children element.It means that if I click on it, do nothing but other I can click and do something. How can I do it?
Upvotes: 0
Views: 936
Reputation: 318182
You can combine the :not()
and :has()
pseudo selectors to do that :
$('.pagination ul li:not(:has(span))').on('click', function() {
// do stuff
});
It does seem easier to just do :
$('.pagination ul li a').on('click', function(e) {
e.preventDefault();
// do stuff
});
Upvotes: 2