I’m given a jQuery object $myObject and a DOM element myElement contained in $myObject.
How can I find the next DOM element contained in $myObject right after myElement?
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.
Pure JavaScript:
Edit: Reading some of your comments, it looks like I may have misunderstood what you are looking for. You mention that your elements are added to
$myObjectusing.add(). It sounds like you are trying to access the elements in the order they were added to$myObject. Is that right? Elements are stored in a jQuery object in the order they appear in the DOM. The order they are added to the jQuery object is not preserved. You can get the next element in the set of matched elements using.index()to find the position ofmyElementand then get the next one:But the next element will be according to DOM order, not the order the elements were added. To get that, you’d need to store the order yourself.
See this demo: http://jsfiddle.net/gilly3/Z96Gd/