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?
Try this:
$("body").on("click", "a:not(a:has(img))", function() {
//do whatever you want here
});
Try this
$('a:not(:has(>img))').click(function(){
alert('click');
});
You can use not
with has
to filter anchors not having img
Live Demo
$("body").on("click", "a:not(a:has(img))", function() {
//do something
alert("");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With