开发者

JQuery: .text() get the html within a node, how do I set the text within a node?

开发者 https://www.devze.com 2022-12-14 15:13 出处:网络
Using JQuery, I can do the following to get the text within my LI $(\"#listingTabs li\").eq(2).text();

Using JQuery, I can do the following to get the text within my LI

$("#listingTabs li").eq(2).text();

How do I set th开发者_StackOverflow社区e text? Because the following doesn't work

$("#listingTabs li").eq(2).text() = 'insert new text';


$("#listingTabs li").eq(2).text("insert new text");

You can also set the innerHTML of the li using

$("#listingTabs li").eq(2).html("<b>insert new text</b>");


$("#listingTabs li").eq(2).text('insert new text');


The text() function works as both a getter and a setter. Try this:

$("#listingTabs li").eq(2).text('insert new text');

If you give it a parameter, it acts as a setter for that property. If you don't, it acts as a getter.

0

精彩评论

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