最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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

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

How do I set the text? Because the following doesn't work

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

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

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

How do I set the text? Because the following doesn't work

$("#listingTabs li").eq(2).text() = 'insert new text';
Share Improve this question asked Dec 15, 2009 at 21:35 BrettkBrettk 3,0532 gold badges18 silver badges3 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6
$("#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)

  1. 暂无评论