Brettk
Brettk

Reputation: 3053

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

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

Upvotes: 1

Views: 517

Answers (3)

zombat
zombat

Reputation: 94147

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.

Upvotes: 4

Justin Swartsel
Justin Swartsel

Reputation: 3431

$("#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>");

Upvotes: 6

danielschemmel
danielschemmel

Reputation: 11116

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

Upvotes: 4

Related Questions