user1611830
user1611830

Reputation: 4867

Trying to use clone - jQuery

Suppose I have an ajax request sending me a callback data data (some text). I have in my html

<tbody class="files-upload">
                        </tbody>
...some tags
<tr class="clonable template-upload">
    <td>
        <span class="preview-upload"></span>
    </td>
</tr>

and

 var clone = $('.clonable').clone();
  $(clone).find(".preview-upload").text(data);
  $('tbody.files-upload').append($(clone));

The problem is that my .files-upload remains empty !

Upvotes: 0

Views: 36

Answers (2)

epsilones
epsilones

Reputation: 11609

I suggest you to wrap your table tags by a table tag. I guess it is the reason why console.log($(clone).find(".preview-upload").length); outputs to 0

Upvotes: 2

Bjorn
Bjorn

Reputation: 71860

The case is probably that your jQuery select statement isn't finding your .preview-upload. I bet if you did this:

console.log($(clone).find(".preview-upload").length);

That it would show you 0. Use the web inspector or firebug to improve your query. A query with 0 found elements is a noop. It will not tell you that it did not add any text nodes, it simply does nothing.

I always do this anyway, but it probably doesn't help with your problem:

$('.preview-upload', clone).text(data);

Upvotes: 1

Related Questions