我怎样才能做到以下几点:

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

使用jQuery哪里regTitle是我的div id?


当前回答

var abc = document.getElementById("regTitle");
abc.innerHTML = "Hello World";

其他回答

以下是你的答案:

//This is the setter of the innerHTML property in jQuery
$('#regTitle').html('Hello World');

//This is the getter of the innerHTML property in jQuery
var helloWorld = $('#regTitle').html();

你可以使用HTML或jquery的文本函数来实现它

$("#regTitle").html("hello world");

OR

$("#regTitle").text("hello world");

如果你有一个jQuery对象,你想渲染而不是现有的内容:然后只是重置内容并追加新的。

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

Or:

$('#regTitle').empty().append(newcontent);
$("#regTitle")[0].innerHTML = 'Hello World';

jQuery的.html()可用于设置和获取匹配的非空元素(innerHTML)的内容。

var contents = $(element).html();
$(element).html("insert content into element");