How to replace innerHTML of a div using jQuery?

前端 未结 13 1829
北恋
北恋 2020-11-22 11:57

How could I achieve the following:

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

Using jQuery where regTitle is my di

13条回答
  •  轮回少年
    2020-11-22 12:27

    Answer:

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

    Explanation:

    $ is equivalent to jQuery. Both represent the same object in the jQuery library. The "#regTitle" inside the parenthesis is called the selector which is used by the jQuery library to identify which element(s) of the html DOM (Document Object Model) you want to apply code to. The # before regTitle is telling jQuery that regTitle is the id of an element inside the DOM.

    From there, the dot notation is used to call the html function which replaces the inner html with whatever parameter you place in-between the parenthesis, which in this case is 'Hello World'.

提交回复
热议问题