Thursday 28 April 2011

jQuery HTML Manipulation


jQuery contains powerful methods (functions) for changing and manipulating HTML elements and attributes.

Changing HTML Content

$(selector).html(content)

The html() method changes the contents (innerHTML) of matching HTML elements.

Example

$("p").html("W3Schools");


Adding HTML content

$(selector).append(content)
The append() method appends content to the inside of matching HTML elements.
$(selector).prepend(content)
The prepend() method "prepends" content to the inside of  matching HTML elements.

Example

$("p").append(" W3Schools");
$(selector).after(content)
The after() method inserts HTML content after all matching elements.
$(selector).before(content)
The before() method inserts HTML content before all matching elements.

Example

$("p").after(" W3Schools.");


jQuery HTML Manipulation Methods From This Page:

FunctionDescription
$(selector).html(content)Changes the (inner) HTML of selected elements
$(selector).append(content)Appends content to the (inner) HTML of selected elements
$(selector).after(content)Adds HTML after selected elements

No comments:

Post a Comment