<a myattr="something">anchor</a>
<a>anchor</a>
$(a[myattr]) does not work
$(a[myattr!="") does not work
$(a[myattr!==undefined) does not work
What works for getting those anchors whose "myattr" are defined and equal to something?
<a myattr="something">anchor</a>
<a>anchor</a>
$(a[myattr]) does not work
$(a[myattr!="") does not work
$(a[myattr!==undefined) does not work
What works for getting those anchors whose "myattr" are defined and equal to something?
Share Improve this question asked Sep 10, 2012 at 15:57 Pablo CollaPablo Colla 2171 silver badge9 bronze badges 6- 6 If you put the selectors between quotes, your first one should work. jsfiddle/ult_bo/nuUrt – Fabrício Matté Commented Sep 10, 2012 at 15:59
- @FabrícioMatté You should post that as an answer.. – Selvakumar Arumugam Commented Sep 10, 2012 at 16:01
- Note that, as far as I remember, void attribute selectors don't work in IE7- (maybe even buggy in IE8 in special binations) – Seimen Commented Sep 10, 2012 at 16:01
- $(a[myattr]) should be like $('a[myattr]') .. Missing the quotes for the selector expression.. – Sushanth -- Commented Sep 10, 2012 at 16:01
- I thought OP could have a more plex problem and just typo'd it, I'm pretty sure the attribute selectors should work even in older IEs as jQuery utilizes Sizzle. – Fabrício Matté Commented Sep 10, 2012 at 16:03
3 Answers
Reset to default 6If you put the selector between quotes, your first one should work.
$('a[myattr]')
Fiddle
http://jsfiddle/Be9Ab/
$("a[myattr]").css("color","red");
Works just fine.
jQuery(function(){
jQuery("a").each(function(){
if(jQuery(this).attr("myattr") && jQuery(this).attr("myattr")!==""){
jQuery(this).addClass("myattr-link").css("color", "red");
}
});
});