Home >Web Front-end >JS Tutorial >jquery method of getting and setting outerhtml_jquery
The example in this article describes how jquery obtains and sets outerhtml. Share it with everyone for your reference. The specific analysis is as follows:
During the development process, jQuery.html() is to obtain the html code under the current node, and does not include the code of the current node itself. However, sometimes we do need it, and we can use jQuery.prop("outerHTML") set up.
Many jQuery users are deeply confused about this issue. Why can't the outerHTML of the html element be directly set like in the DOM among the many convenient methods of getting and setting attributes?
Because there is a built-in attribute outerHTML in the native JS DOM (look at the case, JS is case-sensitive) to get the html code of the current node (including the current node), so you can use jQuery's prop() to get it to
1. jquery gets outerhtml
<div class="test"><p>hello,你好!</p></div> <script> $(".test").prop("outerHTML"); </script>
2. jquery setting outerhtml
$('.test').prop('outerHTML', '<input>');
I hope this article will be helpful to everyone’s jQuery programming.