Given an item
and an array
, I would like to know if
item
exist in
array
.
item
is a jQuery object, e.g. $(".c")
. You can assume that
item.length ==
.
1
array
is an array of jQuery objects, e.g. [$(".a"), $(".b")]
. Each
item in this array may represent 0, 1, or more
objects.
Here is how I thought to implement
this: (live demo
here)
function
inArray(item, arr) {
for (var i = 0; i < arr.length; i++) {
var
items = $.makeArray(arr[i]);
for (var k = 0; k <
items.length; k++) {
if (items[k] == item[0]) {
return
true;
}
}
}
return
false;
}
Can
you find a more elegant implementation?
/>
Example:
HTML:
class="a">Hello
No comments:
Post a Comment