-
Book Overview & Buying
-
Table Of Contents
jQuery 1.4 Reference Guide
These methods are used to remove content from the DOM and replace it with new content.
Get the HTML contents of the first element in the set of matched elements.
.html()
None
A string containing the HTML representation of the element.
This method is not available on XML documents.
In an HTML document, we can use .html() to get the contents of any element. If our selector expression matches more than one element, only the first one's HTML content is returned. Consider the following code:
$('div.demo-container').html();In order for the content of the following <div> to be retrieved, it would have to be the first one in the document.
<div class="demo-container"> <div class="demo-box">Demonstration Box</div> </div>
The result would look like this:
<div class="demo-box">Demonstration Box</div>
Set the HTML contents of each element in the set of matched elements.
.html(htmlString...
Change the font size
Change margin width
Change background colour