Alex Rivera | Logout

Using jQuery, how do I change the elements html value? (div)

Asked 2009-02-11T16:20:36.870
13

Using a ajax request I want to change content of my div.

<div id="d1">202</div>

So I want to change the content to a different number.

$('d1').InnerText???

Also, say I wanted to increment the number, how could I do that? Do I have to convert to int?

Edit
Report

2 Answers

4

Unless you're embedding html like <b>blah</b> I'd suggest using $("#di").text() as it'll automatically escape things like <, > and &, whereas .html() will not.

answered 2009-02-11T17:00:49.987
2

Use the text function:

$("#d1").text($("#d1").text() + 1);
answered 2009-08-03T03:31:37.213

Your Answer