0

I'm building dynamically an UL > LI > a structure, I want to check if on click event there are many other nodes.

I try this:

jQuery('ul.sub-menu li a').click(function(){
    if(jQuery(this).has('.sub-menu').length > 0)
        return false;
});

but doesn't work!

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
mariobros
  • 859
  • 4
  • 12
  • 31
  • 3
    *I want to check if on click event there are many other nodes*: What do you want to check? Which *other* nodes? How many is many? Which relation do these nodes have with the clicked one? What is your HTML structure? Your question cannot be answered because your intend is not clear. *Edit:* Regarding your edit: "doesn't work" is a meaningless error description, which does not help. – Felix Kling Dec 21 '11 at 09:45
  • "doesn't work" isn't a question. Do your own debugging! – Lightness Races in Orbit Dec 21 '11 at 09:54
  • There is a previous question about doing x if a div has children, check it out here: http://stackoverflow.com/questions/1526873/jquery-if-div-id-has-children – Raul Marengo Dec 21 '11 at 09:44
  • @Ramengo Yes, i try with "children" property but still not work! `if ( jQuery('.sub-menu li a').children().length > 0 ) { //do something }` – mariobros Dec 21 '11 at 10:02
  • Might be related to the fact that you are checking a class rather than a specific div id. Assign an ID to the div and try using that #id to evaluate the same function. – Raul Marengo Dec 21 '11 at 10:16

1 Answers1

1
jQuery('ul.sub-menu li a').click(function(){ 
  var has_other_sub_menu = jQuery(this).closest('.sub-menu').siblings().length > 0;
});
voondo
  • 2,533
  • 1
  • 16
  • 21