Ankit Ladhania
Ankit Ladhania

Reputation: 995

how to select all item in consecutive divs with same name using jquery

I'm having a slight problem: I want to select all items consecutively like.

<div class="exp1">
    <div class="inn">
        // some code is here
    </div>
    <div class="inn">
        // some code
    </div> 
    //similar divs
</div>//end of exp1


<div class="exp1">
    <div class="inn">
        // some code is here
    </div>
    <div class="inn">
        // some code
    </div> 
    //similar divs
</div>//end of exp1

There is no typing mistake. So I want to select all the "inn" divs and make some css change like height and width according to their corresponding "exp1" div, but when I am using jQuery it only selects the first one. The jQuery I'm using is:

$('div.exp1 div.inn').each(
                        $(this).css({
            width:$('div.exp1').width()-1,
            height:$('div.exp1').height()-1
            }););

Upvotes: 0

Views: 376

Answers (5)

Tom
Tom

Reputation: 12998

$('div.exp1 div.inn').each(function() {
                    $(this).css({
        width:$(this).parent().width()-1,
        height:$(this).parent().height()-1
        }});

Upvotes: 1

Sanal
Sanal

Reputation: 1

$(document).ready(function(){ $('div.inn').css('width','30px'); });

I think it will fix your problem

Upvotes: 0

sangram parmar
sangram parmar

Reputation: 8726

try this

 $('.inn').each(function(){
   var current_inndiv=$(this);
    current_inndiv.css('width', '30px');

})

Upvotes: 0

Andreih
Andreih

Reputation: 25

Assign the "inn" class to all divs you want to select like this <div class="inn"></div>

Then what you to do is

$('.inn').each(function() {
  $(this).css('width', '30px');
});

Upvotes: 1

Grant Thomas
Grant Thomas

Reputation: 45083

We don't have your jQuery, but based on your markup (and that you've fixed the typo that you insisted didn't exist), the following will select all elements with the class name inn applied:

var elements = $(".inn");

Upvotes: 0

Related Questions