1

I've got a simple piece of HTML, that I retrieve via AJAX. It looks like this:

<div id="hiddencontact">
    <form id="hiddenform"></form>
</div>

So, that's stored in the 'data' variable.

Now I try to run this:

$('#hiddencontact', data);

But it does not work. I do not get the div.

This, however, does work, and returns the form to me:

$('#hiddenform', data);

Why is that? Why is the first element being ignored?

Btw: I'm using jquery 1.7.1

4

2 回答 2

5

为什么第一个元素被忽略?

因为的根节点data就是#hiddencontact它自己。所以你找不到它作为嵌套元素

随着$('#hiddencontact', data);您正在寻找嵌套在的元素data:就像搜索$(data).find('#hiddencontact')

于 2012-08-30T10:24:18.020 回答
0

只需执行此操作$(data);,您将获得整个 div

于 2012-08-30T10:26:10.347 回答