开发者

Editing a div tag

开发者 https://www.devze.com 2023-03-19 02:44 出处:网络
If I have 4 divs: <div class=\"divData\">data 1</div> <div class=\"divData\">data 2</div>

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');
0

精彩评论

暂无评论...
验证码 换一张
取 消