How to use html() Method in JQuery HTML

This article describe about html() Method in JQuery.
  • 2554

HTML use html() method in jQuery

  • html() method sets the html contains of selected elements.

  • html() method is used to return a value.

  • html() method returns the content of the FIRST matched element.

Syntax

$(selector).html()

Example

Following is an example show to use of .html(). it retrieves HTML content from the object

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function ()

{

        $("button").click(function ()

{

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

        });

    });

</script>

</head>

<body>

<p>This is a paragraph.</p>

<button>Get the content of the p element</button>

</body>

</html>

Output1

op1.jpg

Output2

op2.jpg

Using a Function

html() method using function to set the content of all selected elements.

Syntax

$(selector).html(function(index,oldcontent))

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.