jquery , get div with class name and chage text?

Hello i want to change div text but into div it has div again with same class

 <div class="ex"><div class="ex">this text must be change</div></div>    

can you help me pls

Upvotes: 1

Views: 61

Answers (3)

guradio
guradio

Reputation: 15555

$('.ex').parent('div.ex').text('ex');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="ex">
  <div class="ex">this text must be change</div>
</div>

Upvotes: 1

Jai
Jai

Reputation: 74738

You can make a css selector like this:

$('.ex > .ex').html('changed.')
.ex{color:red;}
.ex .ex{color:blue;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ex"><div class="ex">this text must be change</div></div>
<div class="ex">this text must be change</div>
    

Upvotes: 1

Rino Raj
Rino Raj

Reputation: 6264

Working Demo

$('.ex .ex').text('changed')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="ex"><div class="ex">this text must be change</div></div>

Upvotes: 1

Related Questions