Jump to content

Recommended Posts

On my blog: http://www.webprofitideas.com

 

I'm using the jQuery plugin Superfish, and I simply needed a way to select ALL the navi items WITHOUT a sub menu (which slides down).

 

This is how the navigation is laid down:

 

<div id="navi">
<div id="blog_navi">
<ul class="sf-menu">
<li><a>main item 1</a></li>
<li><a>main item 2</a></li>
<li><a>main tiem 3</a> <ul class="children"><li><a>sub-item-1</a></li><li><a>sub-item-2</a></li></ul></li> /* li tag + sub menu here */
<li>main item 4</li>
</ul>
</div>
</div>

 

 

And now I want to select all the li main items in the navi BUT the ones with a sub menu. Logically thinking you'd think that this is the right syntax to do so:

 


jQuery('.sf-menu li:not(:contains(ul))').addClass('noSub');

 

But for some reason this won't work and it will select ALL li tags even the ones containing a ul tag.

 

This on the other hand will give the desired effect:

 

jQuery('.sf-menu li:not(:contains(a))').addClass('noSub');

 

For some reason this will select all the main items without a sub menu EVEN THOUGH every single navigation item CONTAINS an anchor tag.

 

I'm really confused on this one and can simply not understand why this works.

 

If every navi item contains an anchor tag then it should simply select none of them.

 

Any ideas, why this works?

Link to comment
https://forums.phpfreaks.com/topic/235205-why-is-this-jquery-statement-working/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.