The best option is to use .delegate() . Its new event was added in jQuery 1.4.2, and its much better than just a click.
.click () adds a new event for each anchor tag.
. delegate () "waits" for a click (or any event specified) before adding a new event (for a specific click).
$(".controls").delegate("a", "click", function() { var cur_class = $(this).attr("class"); if (cur_class == "pause") { // do something } else if (cur_class == "prev") { // do something } else if (cur_class == "next") { // do something } }
Note: code not tested, read . delegate () in the jQuery documentation for more information.
Maybe you need to add id to <ul> :
( <ul class="controls" id="ul_id"> ), then use $("#ul_id").delegate("a", "click", function() { / ... } .
Hope this helps.
source share