
Untitled
By: a guest on
May 26th, 2012 | syntax:
None | size: 0.95 KB | hits: 20 | expires: Never
jQuery Attribute Contains Selector
<div class="wrapper">
<div class="uct_attr" data-tags="one two three four">stuff</div>
<div class="uct_attr" data-tags="three four">stuff</div>
<div class="uct_attr" data-tags="one three five">stuff</div>
<div class="uct_attr" data-tags="one two six">stuff</div>
<div class="uct_attr" data-tags="four five six">stuff</div>
</div?
// if match 'one'
$('.wrapper .uct_attr[data-tags="one"]').doMatch();
// the rest that didn't match 'one'
$('.wrapper .uct_attr[data-tags!="one"]').doNotMatch();
var $els = $(".wrapper .uct_attr");
$els.filter("[data-tags~='one']").doMatch();
$els.not("[data-tags~='one']").doNotMatch();
<div id="uct_attr" datatags="one two three">
// if match 'one'
$('.wrapper .uct_attr[datatags~="one"]').doMatch();
// the rest that didn't match 'one'
$('.wrapper .uct_attr').not('[datatags~="one"]').doNotMatch();
$('.wrapper').find('div').not('.uct_attr[data-tags="one"]').doNotMatch();