user1321237
user1321237

Reputation:

Why doesn't my DOM get updated when I change the HTML with jQuery?

I have the following:

<div id="info-message"></div>

I am changing the text in between the DIVs like this:

$('#info-message').html = "xxx";

However even though I can step through this in the firebug debugger I don't see any change on the screen and nothing is added when I look with firebug.

Upvotes: 1

Views: 110

Answers (4)

user899205
user899205

Reputation:

You must use html() method:

$('#info-message').html("xxx");

and if you want to append an element and work with its DOM you can use the following:

var contentDiv = $('<div class="content">xxx</div>');
$('#info-message').append(contentDiv);

contentDiv.css('color', 'red');

Upvotes: 1

$('#info-message').html('xxx')

Upvotes: 1

James Allardice
James Allardice

Reputation: 165971

Because html is a method, you need to call it like one:

$('#info-message').html("xxx");

Currently, you are setting the html property of the jQuery object to the string "xxx".

Upvotes: 4

Sergi Papaseit
Sergi Papaseit

Reputation: 16174

The correct usage of the html() jQuery method is:

$('#info-message').html("xxx");

And in case you wanted to retrieve the html of an element:

$('#info-message').html();

Upvotes: 2

Related Questions