0

I have some HTML markup for a set of menu controls that is basically as follows. As you will note, the markup in each <div class="row"> repeats. This repeating code is that same for each menu control set.

<div id="menuModal">
    <div class="row">
        <div class="col-xs-6">
           <i>Control Icon</i>
           <span>Control Label</span>
        </div>
        <div class="col-xs-2">
           <i>Control Icon</i>
           <span>Control Label</span>
        </div>
        <div class="col-xs-2">
           <i>Control Icon</i>
           <span>Control Label</span>            
        </div>
        <div class="col-xs-2">
           <i>Control Icon</i>
           <span>Control Label</span>            
        </div>
    </div>
    <div class="row">
        <div class="col-xs-6">
           <i>Control Icon</i>
           <span>Control Label</span>
        </div>
        <div class="col-xs-2">
           <i>Control Icon</i>
           <span>Control Label</span>
        </div>
        <div class="col-xs-2">
           <i>Control Icon</i>
           <span>Control Label</span>            
        </div>
        <div class="col-xs-2">
           <i>Control Icon</i>
           <span>Control Label</span>            
        </div>
    </div>
</div>

I'm setting the color of each div class="col-xs-6"> control label, EXCEPT for the first of these labels with the following jQuery selectors and method:

$( "#menuModal" ).find( "div.row > div.col-xs-6 > span" ).not( "div.row:eq(0) > div.col-xs-6 > span" ).css( "color", "#669900" );

The jQuery statement above sets the label color of EVERY div class="col-xs-6" label, including the first one. I can't figure out why the .not method selector won't work.

Any ideas? I'm banging my head on this...

  • That's actually weird. A possible explanation is that perhaps jQuery allows only *simple selectors* for `filter` and `not`. – Salman A Aug 15 '16 at 17:56

4 Answers4

1

You may exclude the first row like this:

$( "#menuModal" ).find( "div.row:not(:first) > div.col-xs-6 > span" )
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
1

You can simply use like this:

$( "#menuModal" ).find( "div.row:not(:first) > div.col-xs-6 > span" )
     .css( "color", "#669900" );
Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
1

You can use native CSS selectors instead:

$("#menuModal div.row ~ div.row > div.col-xs-6 > span")

This will skip first div.row even if it is not the first child.

Salman A
  • 262,204
  • 82
  • 430
  • 521
0
$( "#menuModal" ).find( "div.row > div.col-xs-6 > span" ).slice(1).css( "color", "#669900" );
Parithiban
  • 1,656
  • 11
  • 16