Just a quick one. What am I doing wrong here?
$("#content a:not(target=_blank)").live("click", function(){
alert("You clicked an internal link!!")
})
Cheers :)
Just a quick one. What am I doing wrong here?
$("#content a:not(target=_blank)").live("click", function(){
alert("You clicked an internal link!!")
})
Cheers :)
You can use the attribute not equals selector:
$("#content a[target!='_blank']").live("click", function(){
alert("You clicked an internal link!!");
});
the jQuery :not()
selector accepts selectors inside of it, so try something like this:
$('#content a:not([target="_blank"])').live("click", function(){
alert("You clicked an internal link!!")
})
brackets?
$("#content a:not([target=_blank])").live("click", function(){
alert("You clicked an internal link!!")
})
You're missing the square brackets for the attribute selector, and quotes around the value.
$('#content a:not([target="_blank"])')
Single quotes would work here as well.
$("#content a:not([target='_blank'])")
I believe it was version 1.6.0 where attribute quotes became mandatory, in previous versions it was optional, and this broke a lot of my code wen I updated. It seems 1.6.2 or 1.6.1 may have removed this requirement, although the docs say they are still mandatory. Better to do what they say in case backwards support gets removed in a future version.
As a CSS selector however, it is still optional for the most part, so at least get used to using them in jQuery from now on if you haven't already.