If I have 4 divs:
<div class="divData">data 1</div>
<div class="divData">data 2</div>
<div class="divData">data 3</div>
<div class="divData">data 4</div>
I know I can use .length
to find out how many divs are on the page:
alert( $(".divData").length ); // returns 4
Is it possible to ch开发者_开发技巧ange the text in the 3rd div without is having an id and keeping the class name as is?
Yes it is using eq
[docs]:
$(".divData").eq(2).text('foo');
Yes. do $(".divData:eq(2)")
then call your chain functions in order to modify it.
try this
$('.divData').eq(2).text('Your Text Here');
Yes:
$('.divData').eq(2).text('myText');
精彩评论