This article describes how to use html () in jquery to dynamically Replace the content in the html Tag. If you need to know it, you can refer to it. jquery html is equivalent to the js innerHTML method, the details are as follows.
Contents (selector).html (content)
The html () function changes the content of the matched HTML element (innerHTML ).
The Code is as follows: |
Copy code |
<Html> <Head> <Script type = "text/javascript" src = "/jquery. js"> </script> <Script type = "text/javascript"> $ (Document). ready (function (){ $ ("Button"). click (function (){ $ ("P" ).html ("Eiege.com -- jquery column "); }); }); </Script> </Head> <Body> <H2> This is a heading <P> This is a paragraph. </p> <P> This is another paragraph. </p> <Button type = "button"> click here </button> </Body> </Html>
|
The append () function appends content to the matched HTML element.
The Code is as follows: |
Copy code |
<Html> <Head> <Script type = "text/javascript" src = "/jquery. js"> </script> <Script type = "text/javascript"> $ (Document). ready (function (){ $ ("Button"). click (function (){ $ ("P"). append ("<B> Eiege.com </B> ."); }); }); </Script> </Head> <Body> <H2> This is a heading <P> This is a paragraph. </p> <P> This is another paragraph. </p> <Button type = "button"> click here </button> </Body> </Html> |
$ (Selector). prepend (content)
The prepend () function provides the Prepend content to the matched HTML element.
The Code is as follows: |
Copy code |
$ ("P"). prepend (www.hzhuti.com ); |
$ (Selector). after (content)
The after () function inserts HTML content after all matching elements.
The Code is as follows: |
Copy code |
<Html> <Head> <Script type = "text/javascript" src = "/jquery. js"> </script> <Script type = "text/javascript"> $ (Document). ready (function (){ $ ("Button"). click (function (){ $ ("P"). after ("Eiege.com "); }); }); </Script> </Head>
<Body> <H2> This is a heading <P> This is a paragraph. </p> <P> This is another paragraph. </p> <Button type = "button"> click here </button> </Body> </Html> |
These methods are applicable to both XML and HTML documents, except html ().
Method description
AddClass () adds the specified class name to the matching element.
After () inserts content after matching elements.
Append () adds content to the matching element.
AppendTo () adds content to the matched element.
Attr () sets or returns the attributes and values of matching elements.
Before () inserts content before each matching element.
Clone () creates a copy of the Matching Element Set.
Detach () removes the set of matching elements from the DOM.
Empty () deletes all child nodes in the matched element set.
HasClass () checks whether the matching element has the specified class.
Set or return the html content of the matched element set in HTML.
InsertAfter () inserts matching elements to the end of another specified Element Set.
InsertBefore () inserts matched elements in front of another specified Element Set.
Prepend () is used to forward content to each matching element.
PrependTo () is used to forward content to each matching element.
Remove () removes all matching elements.
RemoveAttr () removes the specified attribute from all matched elements.
RemoveClass () removes all or specified classes from all matching elements.
ReplaceAll () replaces all matched elements with matched elements.
ReplaceWith () replaces the matched element with the new content.
Text () sets or returns the content of the matching element.
ToggleClass () adds or deletes a class from a matched element.
Unwrap () removes and replaces the parent element of the specified element.
Val () sets or returns the value of the matching element.
Wrap () wraps matching elements with specified content or elements.
WrapAll () wraps all matching elements with the specified content or element.
Wrapinner () wraps the child content of each matching element with the specified content or element.