Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Answers


jQuey html () methods get the html contents of the first element in the set of matched elements or set the html contents of every matched element.

Syntax:

Return content:

$(selector). html ()

Set content:

$(selector). html (content)

Code sample:

Following code will return html for search result div,

$('.search-result'). html ();


Fowling jQuey html () method set the html contents of every matched element.

Code sample:

Following code sets htmls for all div tags in document,

$("div"). html ("<span>Hello team <b>text here </b></span>"); 

Sets html content using class selector,

$('.search-result'). html ("<span>Hello team <b>text here </b></span>"); 

html () method allows function also to set html content check following code sample for same,

$("#resultDiv"). html (function () {
                    var emphasis = "<em>" + $("p").length + " paragraphs!</em>";
                    return "<p>Result content is " + emphasis + "</p>";
                });

Share your answer


Share as a guest

Please subscribe me to the CodeChef4U.

By creating your new answer, you agree to the privacy policy and terms of service.