Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$("#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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...