Francesco
Francesco

Reputation: 25239

jquery: how to select parent and exclude children

assuming i have

<div class="myclass">
    <div>parent<div>
    <div>parent<div>
    <div>
       parent
       <div>child<div>
    <div>
    <div>parent<div>
</div>

if i wanted to select all the "li" parent excluding the li child...how can i do that?

$(".myclass div") ?

Upvotes: 0

Views: 862

Answers (2)

Valerij
Valerij

Reputation: 27738

use $(".myclass div:has(div)")

Upvotes: 0

Karl Rosaen
Karl Rosaen

Reputation: 4644

Using:

$(".myclass > div")

will select just the direct children instead of all descendants.

Upvotes: 4

Related Questions