During the development process, jquery.html () Gets the HTML code under the current node, does not contain the code of the current node itself, and we sometimes do need to find the JQuery API documentation without any way to get it.
See some people through the parent (). HTML (), if the current element does not have a sibling element also line, if there is that will not work. Background experiments have found a way to solve a jquery, and it is very simple, as follows:
Jquery.prop ("outerhtml");
class="test"><p>hello, Hello! </p></div><script>$ (". Test"). Prop (" outerHTML"); </script>
The output is: <div class= "Test" ><p>hello, Hello! </p></div>
Because the native JS Dom has a built-in property outerhtml (see case, JS is case-sensitive) to get the current node of the HTML code (including the current node), so with jquery prop () can get, after the experiment attr () method is not available, do not believe the words , we can also try, thank you.
Of course, some people use the jquery clone () function with append () to create a node with only one child element, and then take the node's HTML, which is also possible, but the code is cumbersome.
jquery Get outerHTML