Monday, October 15, 2012

jQuery html() Method

How to set and get inner HTML using jQuery

In jQuery we can get inner HTML using html(0 method, This method will return inner HTML only first element in document.

i.e if jQuery found more than one selector then its consider only first selector.

Syntax -
1. For get use .html() - To get inner HTML of selector use this method.
2. For set use - .html(string) - To set inner HTML, with one string parameter, this parameter consider as HTML.

Example 1 - You can see following simple example to see how html() funciton work.

<!DOCTYPE html>
    <script src=""></script>
        function setText() {
            $('message').html('This is testing message');

        function getText() {
            var text = $('message').html();
    <div id="message">This is demo message</div>
    <input type="button" onclick="setText();"/>
    <input type="button" onclick="getText();"/>

No comments:

Post a Comment

Total Pageviews