admin管理员组文章数量:1315978
Not really sure how to phrase this question so it's generic enough. (and will rephrase, after I know what I'm asking). The problem, I believe deals with variables in a JQuery .find()
function.
Problem: you can wrap $()
around an array of DOM elements, or around a jQuery object, but not around an array of jQuery objects
The best I can do, at this time, is provide an example here
The problem code in the previous fiddle, is here:
////////////////Neither of the following works////////////////
//nodelevel = nodesWithMinuses.find('div.node.level' + levelnumber);
nodelevel = $(nodesWithMinuses).find('div.node.level' + levelnumber);
////////////////Neither of the previous works////////////////
Not really sure how to phrase this question so it's generic enough. (and will rephrase, after I know what I'm asking). The problem, I believe deals with variables in a JQuery .find()
function.
Problem: you can wrap $()
around an array of DOM elements, or around a jQuery object, but not around an array of jQuery objects
The best I can do, at this time, is provide an example here
The problem code in the previous fiddle, is here:
////////////////Neither of the following works////////////////
//nodelevel = nodesWithMinuses.find('div.node.level' + levelnumber);
nodelevel = $(nodesWithMinuses).find('div.node.level' + levelnumber);
////////////////Neither of the previous works////////////////
Share
Improve this question
edited Oct 17, 2012 at 9:51
hippietrail
17k21 gold badges109 silver badges179 bronze badges
asked Nov 17, 2011 at 20:19
Ryan SchultzRyan Schultz
3374 silver badges19 bronze badges
3
- 1 What problem? If you don't know what you're asking, don't ask. – user395760 Commented Nov 17, 2011 at 20:21
- 1 Before I let guests visit my house, I tidy it up a bit to make sure it looks reasonably nice. Why do people think that it should be any different for their code? – zzzzBov Commented Nov 17, 2011 at 20:22
- @zzzzBov LOL I've been following you for the past 25 minutes and almost all of your ments have been hostile to condescending. I'd flag them if they weren't so funny. – puk Commented Nov 17, 2011 at 20:30
3 Answers
Reset to default 6Apparently you can wrap $()
around an array of DOM elements, or around a jQuery object, but not around an array of jQuery objects.
Try changing this line:
var nodeWithMinus = thisplusminus.parent().parent();
to this:
var nodeWithMinus = thisplusminus.parent().parent()[0];
This will extract the DOM element and turn nodesWithMinuses
into an array of DOM elements.
The variable nodesWithMinuses
is an array of jQuery objects. You cannot apply jQuery method to anything else then a jQuery object. You have 2 options : either you declare nodesWithMinuses
as a jQuery object and add objects to it via the add
method :
var nodesWithMinuses = $();
//...
nodesWithMinuses.add(element);
// instead of nodesWithMinuses.push(element);
either find a way to convert the array to a jQuery object :
$($.map(nodesWithMinuses,function(el,i){return el.get(0)})).find('div.node.level' + levelnumber);
or traverse the array and search for the element in each object at a time :
var result = $();
$.each(nodesWithMinuses,function(i,el){
result.add(nodesWithMinuses.find('div.node.level' + levelnumber));
});
console.log(result);
In your code, nodeWithMinuses
is an array but you're trying to wrap it in the jQuery function. That doesn't work on arrays. Using a variable in jQuery's find
function is fine.
本文标签:
版权声明:本文标题:javascript - You can wrap $() around an array of DOM elements, or around a jQuery object, but not around an array of jQuery obje 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741987044a2408746.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论