0

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 !

4

2 回答 2

2

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

于 2013-09-16T23:18:50.497 回答
1

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);
于 2013-09-16T23:03:12.760 回答