jquery gets and sets the method outerhtml

  • 2020-05-12 02:09:31
  • OfStack

This example shows how to get and set outerhtml for jquery. Share with you for your reference. The specific analysis is as follows:

In the development process, jQuery.html () is to get the html code under the current node, which does not contain the code of the current node itself. However, we do sometimes need to set it by jQuery.prop ("outerHTML").

Many users of jQuery are puzzled by this question. Why not set outerHTML for html elements directly, as in DOM 1, among the many convenient ways to get and set properties?

Because native JS DOM has a built-in property outerHTML (case sensitive) to get the current node's html code (including the current node), prop() can be obtained using jQuery

1. jquery gets outerhtml


<div class="test"><p>hello , how are you? </p></div>
<script>
$(".test").prop("outerHTML");
</script>

2. jquery sets outerhtml


$('.test').prop('outerHTML', '<input>');

I hope this article is helpful to you in jQuery programming.


Related articles: