user2481398
user2481398

Reputation:

Identify div with no id

I have two parent div with it's corresponding child div's. I want to modify something in my second div's child div but it has no id.How will I do that without affecting the first parent div's child div?

<div class="main">        
    <div id="loggedin" class="container-fluid">
    </div>
</div>
<div class="main">
    <div class="container-fluid">
    </div>        
</div>

Upvotes: 2

Views: 143

Answers (4)

Balachandran
Balachandran

Reputation: 9637

try

$(".main:eq(1) .container-fluid");

or

$(".main:eq(1)").find(".container-fluid");

DEMO

Upvotes: 2

Chakri
Chakri

Reputation: 790

Here is what you need of

$('.main').eq(1).children('div').text()

check this fiddle

For more DOM traversals go through this link

Upvotes: 0

laaposto
laaposto

Reputation: 12213

And a pure javascript solution:

var elems=document.getElementsByClassName("container-fluid");
var item=elems[1];

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82231

You can use .eq() selector here:

$('.main .container-fluid:eq(1)');

or :not selector:

$('.main .container-fluid:not(#loggedin)');

Upvotes: 0

Related Questions