Javascript examples for jQuery Method and Property:html
The html() method sets or returns the innerHTML of the selected elements.
When returning content, it returns the content of the FIRST matched element.
When setting content, it overwrites the content of ALL matched elements.
Parameter | Require | Description |
---|---|---|
content | Required. | new content for the selected elements |
function(index,currentcontent) | Optional. | function that returns the new content for the selected elements |
The following code shows how to change the content of all <p> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").html("Hello <b>world!</b>"); });/*from w w w . j av a2 s . c o m*/ }); </script> </head> <body> <button>Change content of all p elements</button> <p>This is a paragraph.</p> <p>This is another paragraph.</p> </body> </html>