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

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 14  |  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. Is it preferred to use css instead of jquery when both get the same job done?
  2. <style type="text/css">span:hover {background: yellow;}</style>
  3. <span>Hello!</span>
  4.        
  5. <style type="text/css">span.highlight{background:yellow;}</style>
  6. <script type="text/javascript">
  7. $("span").hover(function () {
  8.     $(this).addClass("highlight");
  9.     }, function () {
  10.     $(this).removeClass("highlight");
  11. });
  12. <span>Hello!</span>
  13.        
  14. $("span").hover(function () {
  15.     $(this).addClass("highlight");
  16.     }, function () {
  17.     $(this).removeClass("highlight");
  18. });
  19.        
  20. $("span").hover(function () {
  21.       $(this).animate({width:'100px'}, 500);
  22.       $(".other-div").fadeIn(200);
  23.     }, function () {
  24.       $(this).animate({width:'50px'}, 500);
  25.       $(".other-div").fadeOut(200);
  26. });