views:

6268

answers:

6

Hi,

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?

+12  A: 
$("#di").html('My New Text');

Check out the jQuery documentation.

If you wanted to increment the number, you would do

var theint = parseInt($("#di").html(),10)
theint++;
$("#di").html(theint);

P.S. Not sure if it was a typo or not, but you need to include the # in your selector to let jQuery know you are looking for an element with an ID of di. Maybe if you come from prototype you do not expect this, just letting you know.

Paolo Bergantino
thanks for the # tip, it was an oversight!
+1  A: 
$('#d1').html("Html here");
Logan Serman
+4  A: 

This would changed the inner text of your HTML element.

$('#d1').text(parseInt(requestResponse)++);
Chatu
A: 
jQuery('#d1').html("Hello World");
Shawn Miller
+1  A: 

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.

cdmckay
A: 

Use the text function:

$("#d1").text($("#d1").text() + 1);
Joe Chung