0

I have a problem to bind a click event on each <a> on this 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 is my 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 the a href is execute, never enter on container.find my alert popup never open, the switch case never execute and my addListener never added !

Thank you very much for your helping

2
  • you said you have problem, what is it? doesnt your codes work? return error or what?? please update the question. Commented Apr 6, 2013 at 3:15
  • Only a href open the page and never my alert popup, my switch case never entered and never my addListener is add Commented Apr 6, 2013 at 3:23

2 Answers 2

2

You you are using jquery >= 1.7, use .on()

$('#box_list_menu').on('click', 'a', function(e){
    //Do whatever you want
})
Sign up to request clarification or add additional context in comments.

1 Comment

just a secund i try this !
0

The problem appears to be your selector, box_list_menu:a. This will select any box_list_menu elements that satisfy the :a psuedoclass (which doesn't exist in css or in jQuery). What you want select any a elements under element with the id box_list_menu.

Use this instead

container.find('#box_list_menu a').bind(...)

Or just

$('#box_list_menu a').bind(...)

Notice the space between #box_list_menu and a -- this means to select a elements that are descendants of #box_list_menu.

Further Reading

6 Comments

@LiTHiUM2525 notice the space between the #box_list_menu and the a. That's critical. Your latest edit still has a colon instead of a space.
where you see a space between ?? i have a : not a space
@LiTHiUM2525 yes, that's the problem.
when i use : container.find('#box_list_menu a').bind(...) i obtain : ReferenceError: container is not defined
@LiTHiUM2525 Try replacing container.find(...) with $(...).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.