开发者

Accessing a parent added via wrap function

I have an input field fld. I wrap this field inside a div in one part of my code.

input.wrap('<div>')

In another part of the code I obtain the field 'fld' which is a jQuery object. fld.el contains开发者_如何学C the input field.

Now, I want the div I previously wrapped around this fld. fld.el.parent() does not work for me. Nor does fld.el.parents(). Tried fld.el.closest('div') with no luck.

If I load the input element again via id, I am able to access the parent objects. $('#'+fld.id).parent() works. But I do not want to introduce any ids. Any way in which I can just make use of the fld.el I have and obtain the parent?


What's the ".el" in fld.el.parent() about? Try fld.parent().


Not 100% sure but try:

parentdivs = fld.el.parents("div:first");

OR

parentdivs = fld.parents("div:first");

This will get your first parent div of an item


Without seeing your code and based on the behavior you're describing, I would guess that fld.el is not a jQuery object.

Try:

$(fld.el).parent();

If you're 100% certain it is a jQuery object (and the above doesn't work) you should post your code, or at least recreate your issue using jsfiddle.net

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜