0

I try convert simple string to HTML object for process it with jQuery. My code:

var old_code_text =  $(invoice_template_id).html();
console.log("old text ="+old_code_text);
old_code_text=$(old_code_text);
console.log("old text2 ="+old_code_text.html());

My first alert show me:

old text =<div id="template_invoice">
  <div id="first_head">
    <div id="logo_invoice">
        <img src="../../../images/invoice_logos/logo912131214.PNG" width="200px">
    </div>
    <div id="main_header_info">
....
....
  </div>
</div>

But my second alert show me :

old text2 =
<div id="first_head">
    <div id="logo_invoice">
        <img src="../../../images/invoice_logos/logo912131214.PNG" width="200px">
    </div>
    <div id="main_header_info">
    ....

Then I use old_code_text like it:

   old_code_text.find("#product_invoice_table tbody").empty();

I dont understand where is div with id template_invoice? When I parse string this div always deleted.

Thanks.

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
  • Possible duplicate of [jQuery get html of container including the container itself](https://stackoverflow.com/questions/6459398/jquery-get-html-of-container-including-the-container-itself) –  Sep 18 '17 at 17:27

1 Answers1

0

wrap the container in a dummy p element tag and you will get the container HTML also

var old_code_text = $("#template_invoice").wrap("<p/>").parent().html()
console.log("old text ="+old_code_text);
krishnar
  • 2,537
  • 9
  • 23