Reputation: 11382
I bind a click
function to a link:
$("body").on("click", "a", function() {
//do something
});
Now I am looking for a selector that will only match if the link does not contain an image tag. So kind of similar to a:not(img)
but img
being the child element.
How can I do that?
Upvotes: 10
Views: 961
Reputation: 148140
You can use not
with has
to filter anchors not having img
$("body").on("click", "a:not(a:has(img))", function() {
//do something
alert("");
});
Upvotes: 1
Reputation: 14827
Try this:
$("body").on("click", "a:not(a:has(img))", function() {
//do whatever you want here
});
Upvotes: 12
Reputation: 2132
Try this
$('a:not(:has(>img))').click(function(){
alert('click');
});
Upvotes: 1