jQuery’s .wrap() method returns the original set of elements for chaining purposes.
What is the most elegant way to return the original set of elements + the wrapped elements instead?
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.
If I understand you correctly, you’ll need
parent()andandSelf().parent()will retrieve the parent for each element in the collection.andSelf()will add the former collection to the new collection.$("div.elements-to-wrap").wrap('<div class="wrapper" />').parent().andSelf();Now, you have a new collection that contains both
div.elements-to-wrapand all thediv.wrapperthat wrap the former elements.