By tonyf

2009-08-20 23:51:36 8 Comments

How could I achieve the following:

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

Using jQuery where regTitle is my div id?


@Cine 2011-08-11 10:34:11

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');



@Kevin Panko 2011-09-08 20:51:02

Good place to use itemtoReplaceContentOf.empty();

@kmoser 2017-08-24 13:25:11

Is newcontent is a jQuery object? This isn't clear.

@Cine 2017-08-29 03:17:18

@kmoser In the first example, newcontent is indeed a jquery object. In the second example it can be of type htmlString or Element or Text or Array or jQuery as per

@Kamil Kiełczewski 2020-06-12 08:51:03

Pure JS and Shortest

Pure JS

regTitle.innerHTML = 'Hello World'

regTitle.innerHTML = 'Hello World';
<div id="regTitle"></div>


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

// note: no quotes around regTitle
$(regTitle).html('Hello World'); 
<script src=""></script>

<div id="regTitle"></div>

@Nikit Barochiya 2017-03-17 05:36:48


$( document ).ready(function() {
  $('.msg').html('hello world');
    <!DOCTYPE html>
        <script src=""></script>    
        <div class="msg"></div>

@Alireza 2019-01-31 11:38:27

jQuery has few functions which work with text, if you use text() one, it will do the job for you:

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

Also, you can use html() instead, if you have any html tag...

@Pavel Donchev 2018-01-21 15:37:17

Just to add some performance insights.

A few years ago I had a project, where we had issues trying to set a large HTML / Text to various HTML elements.

It appeared, that "recreating" the element and injecting it to the DOM was way faster than any of the suggested methods to update the DOM content.

So something like:

var text = "very big content";
$("<div id='regTitle'>" + text + "</div>").appendTo("body");
<script src=""></script>

Should get you a better performance. I haven't recently tried to measure that (browsers should be clever these days), but if you're looking for performance it may help.

The downside is that you will have more work to keep the DOM and the references in your scripts pointing to the right object.

@Al.UrBasebelon Tomeh 2017-09-21 12:26:52

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

@jitendra varshney 2017-02-03 06:15:43

you can use either html or text function in jquery to achieve it

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


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

@Somnath Muluk 2016-09-07 16:41:05

There are already answers which give how to change Inner HTML of element.

But I would suggest, you should use some animation like Fade Out/ Fade In to change HTML which gives good effect of changed HTML rather instantly changing inner HTML.

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.

function changeInnerHtml(elementPath, newText){
    $(elementPath).fadeOut(500, function() {

@Webeng 2016-06-22 02:37:03


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


$ 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'.

@Pratik 2014-10-16 12:14:11

jQuery's .html() can be used for setting and getting the contents of matched non empty elements (innerHTML).

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

@Gellie Ann 2016-12-01 01:03:57

The open and close parenthesis after html saved me. So remember folks those two are important.

@zombat 2009-08-20 23:52:47

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'); 

@Anoop Joshi 2015-09-18 12:33:14

" but keep the html structure" . can you explain?

@Gorgsenegger 2016-01-14 14:04:46

From the jQuery API documentation (, text() is different as: Unlike the .html() method, .text() can be used in both XML and HTML documents.. Furthermore, according to…, jQuery.html() treats the string as HTML, jQuery.text() treats the content as text.

@Machavity 2017-03-31 18:29:11

@dane 2013-11-27 08:03:08

Here is your answer:

//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();

@Zed 2009-08-20 23:52:40

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

Related Questions

Sponsored Content

70 Answered Questions

[SOLVED] How to replace all occurrences of a string?

66 Answered Questions

[SOLVED] How do I check whether a checkbox is checked in jQuery?

58 Answered Questions

[SOLVED] How do I check if an element is hidden in jQuery?

32 Answered Questions

[SOLVED] jQuery scroll to element

58 Answered Questions

[SOLVED] How do I redirect to another webpage?

42 Answered Questions

[SOLVED] Is there an "exists" function for jQuery?

  • 2008-08-27 19:49:41
  • Jake McGraw
  • 774018 View
  • 2816 Score
  • 42 Answer
  • Tags:   javascript jquery

28 Answered Questions

[SOLVED] What does "use strict" do in JavaScript, and what is the reasoning behind it?

37 Answered Questions

28 Answered Questions

[SOLVED] How can I refresh a page with jQuery?

Sponsored Content