I have a UserControl. Ex:
<div id="divItem"> some html </div>
The ajax request return new html of this UC from server. Ex:
<div id="divItem"> new html </div>
I want to replace the old html by the new one. How could I do that. Thanks.
The outerHTML is often used to replace the element and its contents completely. It differs from the innerHTML as innerHTML only represent the HTML of contents of an element, while outerHTML includes the HTML of element itself with its descendants.
jQuery text() Method Tip: To set or return the innerHTML (text + HTML markup) of the selected elements, use the html() method.
To get HTML content of an element using jQuery, use the html() method. The html() method gets the html contents of the first matched element.
With jQuery, you can use the . append() method to insert the specified HTML as the last child of the div container.
If you also return the div divItem
$("#divItem").replaceWith("NEW HTML");
Put the new HTML on the spot or replace the innerHTML, since they got the same container:
$("#divItem").html($("NEW HTML").html());
If you dont return the div divItem
Just put the new html:
$("#divItem").html("NEW HTML");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With