views:

64

answers:

1

This code is supposed to add a class attribute to the span element "saved" with the right id. but somewhat its not doing so. Perhaps something I am missing, cant seem to figure it out.

<script type="text/javascript">

jQuery(function($){ 

  $("a[id^='savebook-']").click(function(){
    match = this.id.match(/savebook-(\d+)/);
    savedclass = $("span#saved-"+match[1])
    savedclass.addClass("saved");
  });

});
</script>

Sample usage

<li><span class="save">
   <a href="#" id="savebook-1" rel="nofollow" class="button">Save Book</a>
   <span id="saved-1" >&nbsp;&nbsp;&nbsp;</span>
</span></li>
+1  A: 

You need to return false; from the click() function to prevent the default action. Apart from that, it works for me (on Google Chrome).

Greg