Net-informations.com
SiteMap  | About    

jQuery HTML Method



jQuery provide 3 methods to set or Get the content from a DOM element i.e. text() , html() and val() . jQuery html() method get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element. Also, by using HTML() with a jQuery object you can replace the contents of any container element like the < div > or < p >, < span > and others. When this method is used to set content, it overwrites the content of ALL matched elements. It is important to note that This method uses the browser's innerHTML property . Some browsers may not return HTML that exactly replicates the HTML source in an original document.

Syntax

Get HTML Contents with html() Method

run this source code Try it Yourself


Outer Div
Inner Div

Full Source

Set HTML Contents with html() Method

run this source code Try it Yourself
Outer Div
Inner Div

Full Source

Difference between jQuery: text() and html() ?

  1. .text() can be used in both XML and HTML documents.
  2. .html() is only for html documents.








net-informations.com (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.