0

I've used $.unique before, but this timne, I can't get it to work.

http://jsfiddle.net/tNXZt/

I get an array of objects, but it does not seem to do anything with them. I hope you can help me here.

Thanks

3
  • I don't know if this causes the error but you have duplicate IDs in your example. Commented Mar 13, 2012 at 10:17
  • It's only for testing and one of them should be removed by the unique function. Commented Mar 13, 2012 at 10:22
  • Yes, but you have to think of the fact that other people might not take care of cases like that as they are not valid HTML. Commented Mar 13, 2012 at 10:24

1 Answer 1

2

$.unique removes duplicates of a node, but there are not duplicate nodes inside the array, there are 3 different nodes. 2 nodes are not unique when they consist of the same markup, they must be the same DOMNode

for example here you would have duplicates:

[$(".test").get(0),
 $(".test").get(0)] 
Sign up to request clarification or add additional context in comments.

5 Comments

Exactly The reason api.jquery.com/jQuery.unique works is because the same instances are added to an array not because of the markup being the same
Okay, Thank you for the explanation. "Sorts an array of DOM elements, in place, with the duplicates removed" - jQuery.com. If I have 2 elements with the same id's, I think these are dublicates. Maybe I'm wrong. Did you look at this: api.jquery.com/jQuery.unique
You're wrong, it doesn't matter what ID the nodes have, they must be the same node. the comparision of nodeA===nodeB must return true, what only will happen on the same nodes.
but we use .get() to put all objects into an array, so does not make sense.
It doesn't make sense how you put it into the array, the only thing that matters is what will be inside the array, and there are no duplicates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.