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

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.30 KB  |  hits: 9  |  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 select class with a number. e.g. foo1, foo2, foo3, foo4
  2. <div class="foo1"><div class="zxcv1"></div></div>
  3. <div class="foo2"><div class="zxcv2"></div></div>
  4. <div class="foo3"><div class="zxcv3"></div></div>
  5. <div class="foo4"><div class="zxcv4"></div></div>
  6. <div class="foo5"><div class="zxcv5"></div></div>
  7. <div class="foo6"><div class="zxcv6"></div></div>
  8.  
  9. <script type="text/javascript">
  10.         for (var i = 1; i < 6; i++) {
  11.         $(".foo"+i).hover(
  12.                 function ()
  13.                 {
  14.                     $(".zxcv"+i).fadeIn();
  15.                 }, function ()
  16.                 {
  17.                     $(".zxcv"+i).fadeOut();
  18.                 });
  19.         }
  20. </script>
  21.        
  22. $("div[class^='foo']").hover(function() {
  23.     $(this).find("div[class^='zxcv']").fadeIn();
  24. }, function() {
  25.     $(this).find("div[class^='zxcv']").fadeOut();
  26. });
  27.        
  28. for (var i = 1; i < 6; i++) {
  29.     (function(i) {
  30.         $(".foo"+i).hover(
  31.                 function ()
  32.                 {
  33.                     $(".zxcv"+i).fadeIn();
  34.                 }, function ()
  35.                 {
  36.                     $(".zxcv"+i).fadeOut();
  37.                 });
  38.     })(i);
  39. }
  40.        
  41. $("[class^='foo']").hover(
  42.     function () {
  43.         $(this).find("[class^='zxcv']").fadeIn();
  44.     }, function () {
  45.         $(this).find("[class^='zxcv']").fadeOut();
  46.     }
  47. );