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

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 15  |  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. Using jQuery to change src on all classes except for current click
  2. $(function(){
  3.     $(".img-swap").live('click', function() {
  4.         if ($(this).attr("class") == "img-swap") {
  5.             this.src = this.src.replace("_off","_on");
  6.         } else {
  7.             this.src = this.src.replace("_on","_off");
  8.         }
  9.     });
  10. });
  11.        
  12. <div id="feedback-topic.buttons">
  13.     <a href="#bug"><img src="lib/feedback-bug_off.jpg" alt="bug" width="75" height="49" border="0" class="img-swap" /></a>
  14.     <a href="#content"><img src="lib/feedback-site_content_off.jpg" alt="bug" width="121" height="49" border="0" class="img-swap" /></a>
  15.     <a href="#suggestion"><img src="lib/feedback-suggestion_off.jpg" alt="bug" width="117" height="49" border="0" class="img-swap" /></a>
  16. </div>
  17.        
  18. this.src = this.src.replace('_off', '_on');
  19.  
  20. $('.img-swap').not(this).attr('src', function(index, attr) {
  21.     return attr.replace('_on', '_off');
  22. });