Say,I have 5 paragraphs in the page.
if I execute:
p_array=$('p');
second_p=$('p:eq(1)');
$.inArray(second_p,p_array);
I get -1.
Any explanation?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Neither
p_arraynorsecond_pare arrays.They are jQuery objects.
More specifically,
p_arrayis a jQuery object containing a set of 5 DOM nodes.second_pis a jQuery object containing a set of 1 DOM node.$.inArraycan function on these jQuery sets of nodes, but you can’t compare a set against a set.If you extract that one DOM node using the array subscript operator (
jQueryObj[i]), then you’re no longer comparing a set against a set:See a live demo here.