0

I have recursive HTML, I know ID of outer most DIV. In below HTML i want to select all DIV with class "citem" expect "citem" inside inner "Popup"

<div id="pop1" class="Popup">
    <div class="container">
        <div class="citem">child item-1</div>

        <div class="Popup">
            <div class="container">
                <div class="citem">child inner item-1</div>
            </div>
        </div>

        <div>
            <div class="citem">child item-2</div>
        </div>

    </div>
</div>

<script type="text/javascript">
    if (typeof $ != "undefined") {
        $(function () {

            var Parent = $("#pop1");
            var Container = $(Parent.find(".container:first"));

            Container.find(".citem").not(".Popup .citem").each(function () {
                alert($(this).html());
            });

        });
    }
</script>

Using above code no item is selected, but i want output to be "child item-1" and "child item-2".

Any idea, what how to write query for this. i don't want to select all item and then check who is parent etc..

user1760384
  • 107
  • 2
  • 9

2 Answers2

1

The > selector will only catch the first level children.

jQuery('.container > .citem')

Will not match an item with class .citem unless his parent has class .container.

ffflabs
  • 17,166
  • 5
  • 51
  • 77
0

your main parent element has a class of "Popup" which disqualifies all citems

<div id="pop1" class="Popup">

so

Container.find(".citem").not(".Popup .Popup .citem").each(function () {

should work

jakealbaugh
  • 256
  • 1
  • 7