开发者

Jquery li element id

I am using a jquery contextmenu plugin for right click menus which I am trying to add to each li element of an unordered list with the ID mailbox. The code I have is:

    $("#mailbox > li").contextMenu('myMenu1', {
      bindings: {
    'open': function(t) {
      alert('Trigger was '+t.id+'\nAction was Open');
    }
    //CODE SNIPPED
    });

My assumption is that this should alert the id of the list element that the contextMenu was called from, however 开发者_开发问答it is returning an empty string. Am I accessing/assigning these correctly?

t is an object HTMLLIElement in the context above by the way.

Cheers, Gazler.


try using "#mailbox li" as your selector. the reason is that #mailbox doesn't have any children of li

element > subelement is for direct children of the element only. in this case, the direct child of #mailbox would probably be ul and not li which would be a grand child. element subelement selects all descendants, not just the direct children.

check it out here: http://docs.jquery.com/Selectors/child#parentchild
and here: http://docs.jquery.com/Selectors/descendant#ancestordescendant

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜