jason
jason

Reputation: 379

CSS select all li which not contains a tag

I want to select all li which not contains a tag in css:

ul.sf-menu li:not(a)

But looks like it is not working.

Need help

<ul class="sf-menu sf-js-enabled sf-shadow">
    <li>
        <a href="/ ">
    </li>
    <li> need to select this li because it is not contains a href
        A 
        <ul style="visibility: visible; display: block">
            <li>
                <a href="/B-1">
            </li>
            <li>
                <a href="/B-2">B-2</a>
            </li>
         </ul>
      </li>
 <li>

Upvotes: 1

Views: 6307

Answers (1)

scottheckel
scottheckel

Reputation: 9244

Two things

1) Your selector doesn't match the question you're asking. It currently selects every LI that is not an Anchor. This should be every LI on the page.

2) What you want can't be done with CSS right now. Your best bet would be to use some JavaScript to do this. For instance, the following jQuery would work.

$("ul.sf-menu li:not(:has(a))").doSomething()

Upvotes: 7

Related Questions