good day. there is such a markup structure:

<div class="container"> <div class="item1">...</div> <div class="item2">...</div> <div class="item3">...</div> </div> 

How to get html() specific item , but with a parent block? those. now $(this).html() will return to me ... but I need to get <div class="item1">...</div> how to do this? (there is an opportunity for jsʻom to draw the parent block, but suddenly block attributes may be needed, the structure for obtaining such a block is of interest)

  • one
    outerHTML - Grundy
  • Thank you, your comment brought me to one article, there was a simpler way: $ (". item1"). get (0) - Maximmka
  • the get method returns the HTMLElement itself, not the markup (string) - in the question it corresponds to this . - Grundy

1 answer 1

 <div class="container"> <div class="item1">...</div> <div class="item2">...</div> <div class="item3">...</div> </div> <script> alert($('.item1').get(0).outerHTML); </script> 

.get() returns an array of found values.

.get(0) - takes the first element of the array, the jQuery object.

.outerHTML - returns the complete HTML element, including the content.

  • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky