An undocumented selector for jQuery – Contains Word
Here’s a useful and as yet undocumented feature of jQuery’s attribute selector, the contains word feature – here’s how it works:
suppose you want to select a series of elements based on a class or rel or whatever. In this case I want to select all the links with the class .mylinks – but only those with the rel containing ‘something’:
<script type="text/javascript" charset="utf-8">
$(function() {
//contains word
$(‘.mylinks[rel~=something]‘).addClass(‘foundyou’); //note the important selector: ~=
});
</script>
$(function() {
//contains word
$(‘.mylinks[rel~=something]‘).addClass(‘foundyou’); //note the important selector: ~=
});
</script>
Developer by day, husband and dad by night and dreaming about sport inbetween.