html - jQuery how to bind all anchors in a div -
i have problem bind click event on each <a> on div:
<div id="box_list_menu" class="boxlistmenu"> <a href="/profile/00000000-0000-0000-0000-000000000001/grantaccesstoprivatephotos/index.php?tid=${id}&un=${name}" id="${id}_grantaccessprivatephotos" rel="link" class="boxlistmenu_grantaccessprivatephotos" title="donner accès à vos photos privées"></a> <a href="/profile/00000000-0000-0000-0000-000000000001/denyaccesstoprivatephotos/index.php?tid=${id}&un=${name}" id="${id}_denyaccessprivatephotos" rel="link" class="boxlistmenu_denyaccessprivatephotos" title="retirer l'accès à vos photos privées"></a> <a href="/profile/00000000-0000-0000-0000-000000000001/block/index.php?tid=${id}" id="${id}_unblock" rel="link" class="boxlistmenu_block" title="bloquer ce membre"></a> <a href="/profile/00000000-0000-0000-0000-000000000001/unblock/index.php?tid=${id}" id="${id}_block" rel="link" class="boxlistmenu_unblock" title="débloquer ce membre"></a> <a href="/profile/report/00000000-0000-0000-0000-000000000001/index.php?tid=${id}&un=${name}" rel="link" class="boxlistmenu_report" title="signaler ce profil à un administrateur"></a> </div> this jquery code:
container.find('#box_list_menu:a').bind("click", function (e) { e.stoppropagation(); var t = this.id.split("_"); var profileid = t[0]; var action = t[1]; var btn = $(this); btn.trigger("blur").attr("disabled", "disabled").addclass("inactive").find("b").html(bsctexts.search.pleasewait); alert("boxlist_menu action = " +action+ " e = " +e); switch (action) { case "block": bsc.event.addlistener(bsc.menu.listenertypes.block, "profile", function (e) { $("#" + profileid + "_block").hide(); $("#" + profileid + "_unblock").show(); btn.removeattr("disabled").removeclass("inactive").find("b").html(btn.attr("title")); }); bsc.menu.blockprofile(e, profileid); break; case "unblock": bsc.event.addlistener(bsc.menu.listenertypes.unblock, "profile", function (e) { $("#" + profileid + "_unblock").hide(); $("#" + profileid + "_block").show(); btn.removeattr("disabled").removeclass("inactive").find("b").html(btn.attr("title")); }); bsc.menu.unblockprofile(e, profileid); break; case "grantaccessprivatephotos": bsc.event.addlistener(bsc.menu.listenertypes.grantaccessprivatephotos, "profile", function (e) { $("#" + profileid + "_grantaccessprivatephotos").hide(); $("#" + profileid + "_denyaccessprivatephotos").show(); btn.removeattr("disabled").removeclass("inactive").find("b").html(btn.attr("title")); }); bsc.menu.grantaccesstoprivatephotos(e, profileid); break; case "denyaccessprivatephotos": bsc.event.addlistener(bsc.menu.listenertypes.denyaccessprivatephotos, "profile", function (e) { $("#" + profileid + "_denyaccessprivatephotos").hide(); $("#" + profileid + "_grantaccessprivatephotos").show(); btn.removeattr("disabled").removeclass("inactive").find("b").html(btn.attr("title")); }); bsc.menu.denyaccesstoprivatephotos(e, profileid); break; default: } return false; }); only href execute, never enter on container.find alert popup never open, switch case never execute , addlistener never added !
thank helping
the problem appears selector, box_list_menu:a. select box_list_menu elements satisfy :a psuedoclass (which doesn't exist in css or in jquery). want select a elements under element id box_list_menu.
use instead
container.find('#box_list_menu a').bind(...) or just
$('#box_list_menu a').bind(...) notice space between #box_list_menu , a -- means select a elements descendants of #box_list_menu.
further reading
Comments
Post a Comment