Ambika Tewari
Ambika Tewari

Reputation: 251

Select div having similar class name but no div id

Parent Class inddetails-wrapper clearfix has two divs which as further classes having same name. I want to select first class col-md-6 nopadding. How should I do that ?

Below is the code:

<div class="inddetails-wrapper clearfix">
    <div>
        <div class="col-md-6 nopadding">...</div>
    </div>
    <div>
        <div class="col-md-6 nopadding">...</div>
    </div>
</div>

Upvotes: 2

Views: 52

Answers (2)

Zeeshan Adil
Zeeshan Adil

Reputation: 2115

as this question was tagged under jquery You can select the first element inside <div class="inddetails-wrapper clearfix"> using Jquery like this:

var firstChild = $( ".inddetails-wrapper.clearfix div" ).first(); 

and you can play with firstChild using more jquery properties depending upon what do you need.

Upvotes: 0

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167172

You can use :first-child:

.inddetails-wrapper div:first-child .col-md-6 {
  background: #f00;
}
<div class="inddetails-wrapper clearfix">
  <div>
    <div class="col-md-6 nopadding">...</div>
  </div>
  <div>
    <div class="col-md-6 nopadding">...</div>
  </div>
</div>

Upvotes: 2

Related Questions