How to replace innerHTML of a div using jQuery?

How could I achieve the following:

document.all.regTitle.innerHTML = 'Hello World';

Using jQuery where regTitle is my div ID?


$("#regTitle").html("Hello World");

The html() function can take strings of HTML, and will effectively modify the .innerHTML property.

$('#regTitle').html('Hello World');

However, the text() function will change the (text) value of the specified element, but keep the html structure.

$('#regTitle').text('Hello world'); 

If you instead have a jquery object you want to render instead of the existing content. Then just reset the content and append the new.

var itemtoReplaceContentOf = $('#regTitle');
itemtoReplaceContentOf.html('');
newcontent.appendTo(itemtoReplaceContentOf);

Or:

$('#regTitle').empty().append(newcontent);
链接地址: http://www.djcxy.com/p/64396.html

上一篇: 固定的位置,但相对于容器

下一篇: 如何使用jQuery替换div的innerHTML?