How could I achieve the following:
document.all.regTitle.innerHTML = 'Hello World';
Using jQuery where regTitle
is my div
id?
To set the value of innerHTML property, you use this syntax: element. innerHTML = newHTML; The setting will replace the existing content of an element with the new content.
For replacing innerHTML of a div with jquery, html() function is used. After loading the web page, on clicking the button content inside the div will be replaced by the content given inside the html() function.
When . html() is used to set an element's content, any content that was in that element is completely replaced by the new content. Additionally, jQuery removes other constructs such as data and event handlers from child elements before replacing those elements with the new content.
First, use the html() function instead of the text() function. Second, point your selector to the right node, something like . portlet-content . content_regular table .
Answer: Use the jQuery html () Method You can simply use the jQuery html () method to replace innerHTML of a div or any other element. The jQuery code in the following example will replace the innerHTML of a DIV element having id pageTitle with an HTML heading on click of the button. Let's try it out:
After loading the web page, on clicking the button content inside the div will be replaced by the content given inside the html () function. Writing code in comment? Please use ide.geeksforgeeks.org , generate link and share the link here.
The dot notation calls the html () method to replace the inner html with the parameter placed between, i.e. Demo here. The html () here modifies the .innerhtml.
Use animation to change Inner HTML $ ('#regTitle').fadeOut (500, function () { $ (this).html ('Hello World!').fadeIn (500); }); If you have many functions which need this, then you can call common function which changes inner Html.
$("#regTitle").html("Hello World");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With