0

Possible Duplicate:
How to check if jQuery object exist in array?

is there any way to determine if a dom element is in an array of dom elements?

i.e.

$(".container img").each(function(){
   views.push($(this).clone());
});

creates an array of cloned image elements. I now want to check if a new image element is in that array?

Thanks

2
  • views.indexOf( yourImage ) !== -1 Commented Nov 1, 2012 at 15:53
  • You don't like inArray()? You already wrote it in the title... Commented Nov 1, 2012 at 15:53

1 Answer 1

2
$(".container img").each(function(){
    if(jQuery.inArray($(this), views) === -1)
    {
        views.push($(this).clone());
    }
});

or check How to check if jQuery object exist in array? for other solutions.

For your use check out http://jsfiddle.net/hxAg4/34

Sign up to request clarification or add additional context in comments.

9 Comments

@Christoph sorry, my copy from textwrangler didn't work properly. Fixed.
can you tell me why this isn't working then please? jsfiddle.net/hxAg4/18
@Seglespaan can you create an jsfiddle.net with your code and html?
ahh, you edited the comment. Give me a minute, jsfiddle seems to be down right now.
@Seglespaan I cannot run the code but I can see it. jsfiddle is still not working properly. However, you have $('.container') but only have id="container". . is for a class while # is for id
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.