Differences between jquery append () and html () methods, jqueryappend
Append (content): The method inserts the specified content at the end of the selected element (still inside). Many friends think that append is similar to html, in other words, append is added based on the original content, while in html, it replaces all the current content.
Definition and usage
The append () method inserts the specified content at the end of the selected element (still inside.
$ (Selector). append (content)
Add content using functions
Use a function to insert content at the end of a specified element.
Syntax
$ (Selector). append (function (index, html ))
Instance code:
<script src="/jquery.min.js" type="text/javascript"></script><style>.imgFocus{border: 1px solid #eee;}</style><p> </p><script type="text/javascript">var showimg = "<div class='imgFocus'>123456</div>";$("p").append(showimg);</script>
The html () method returns or sets the content of the selected element (inner HTML ).
If no parameter is set for this method, the current content of the selected element is returned.
Returned Element Content
When this method is used to return a value, it returns the content of the First Matching Element.
Syntax
Optional (selector).html ()
Set the content of all p elements:
$(".btn1").click(function(){ $("p").html("Hello <b>world</b>!");});
Clear in specified Element
$ ("A [href $ = 'logout. asp '] "). click (function (event) {event. preventDefault (); $. get ("/xxlr/Logout. asp "," ", function (data, textStatus) {if (data = 1) {// indicates that the logout is successful. ('your message'}.html (""); $ ("# userlogin> div "). show ();} else {$ ('# message '). append ("<p> <strong> logout failed. Please try again! </Strong> </p> ");}});});
In jquery, how does one use the append () method to add new elements? $ ('# Id') cannot be obtained in html?
. Append (content)
A simple example
<! DOCTYPE html>
<Html>
<Head>
<Style>
P {background: yellow ;}
</Style>
<Script src = "code.jquery.com/jquery-1.4.4.js"> </script>
</Head>
<Body>
<P> I wowould like to say: </p>
<Script>
$ ("P"). append ("<strong> Hello </strong> ");
</Script>
</Body>
</Html>
========================================================== =
I tried it locally to get the value.
<Div id = "con"> </div>
<Div id = "result"> </div>
<Script>
$ ("# Con"). append ("<div id = 'hello'> hello </div> ");
$ ("# Result" ).html ($ ("# hello" ).html ());
</Script>
You can see that there are two Hello
Use the append () method of jQuery to append the html, and use the selector to obtain the appended element.
For example, in the following example, the appended element is directly added as a string.
$ ('Body'). append ('<div class = "clickme"> Another target </div> ');
You can declare a character and obtain the element to be appended.