Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 26th, 2012  |  syntax: None  |  size: 0.95 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery Attribute Contains Selector
  2. <div class="wrapper">
  3.  <div class="uct_attr" data-tags="one two three four">stuff</div>
  4.  <div class="uct_attr" data-tags="three four">stuff</div>
  5.  <div class="uct_attr" data-tags="one three five">stuff</div>
  6.  <div class="uct_attr" data-tags="one two six">stuff</div>
  7.  <div class="uct_attr" data-tags="four five six">stuff</div>
  8. </div?
  9.        
  10. // if match 'one'
  11. $('.wrapper .uct_attr[data-tags="one"]').doMatch();
  12. // the rest that didn't match 'one'
  13. $('.wrapper .uct_attr[data-tags!="one"]').doNotMatch();
  14.        
  15. var $els = $(".wrapper .uct_attr");
  16. $els.filter("[data-tags~='one']").doMatch();
  17. $els.not("[data-tags~='one']").doNotMatch();
  18.        
  19. <div id="uct_attr" datatags="one two three">
  20.        
  21. // if match 'one'
  22. $('.wrapper .uct_attr[datatags~="one"]').doMatch();
  23. // the rest that didn't match 'one'
  24. $('.wrapper .uct_attr').not('[datatags~="one"]').doNotMatch();
  25.        
  26. $('.wrapper').find('div').not('.uct_attr[data-tags="one"]').doNotMatch();