Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery is deleting elements

I've got a problem with jQuery. I need to copy some code, to append is somewhere else.

The source I like to take a copy from is like this:

<div id="copyCode" style="display: none">
    <div class="ofPagedataTable">
        <tr class="page copy">
            <td class="id"><input type="text" /></td>
            <td class="sprache"><input type="text" /></td>
            <td class="description"><input type="text" /></td>
            <td class="title"><input type="text" /></td>
            <td class="keywords"><input type="text" /></td>
        </tr>
    </div>
</div> 

The jQuery I'm using is like this:

$('.addPageToPagedata').click(function(){
    html = $("#copyCode").children(".ofPagedataTable").html();
    target = $('.pagedata tbody').children(':last');    
    $(html).appendTo(target);
    });

It's kind of working, but jQuery is taking away the <tr> and <td> Elements and it is appending just:

<input type="text">
<input type="text">
<input type="text">
<input type="text">
<input type="text">

I'dont know what to do. It would be nice if someone can give me a suggestion how to solve this.

Thank you!

like image 325
Tim Takel Avatar asked Sep 01 '26 00:09

Tim Takel


2 Answers

I don't think jQuery remove anything. You html is not valid. You can't put td and tr here. Your browser just remove this elements by itself.

like image 105
Magus Avatar answered Sep 03 '26 15:09

Magus


try wrapping the tr in <table> tags, to make the html valid.

like image 20
dave Avatar answered Sep 03 '26 15:09

dave