I'm new to JQuery. Got a simple question.
<div id="result"> hello </div>
...
$("#result").html()
$("#result").html()
substitutes the text inside div tag to the returned result I need, but how do I adding the returned result in div tag instead of changing it completely? I guess there might be another function to do this job. What is it? Thanks.
Just use
$("#result").append("Some text");
And this will add Some text to the end of your string. So it would look like hello Some text
You can use callback function of .html()
:
$("#result").html(function(i,oldhtml){
return oldhtml + "<span>abc</span>";
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.