I want to enclose using jquery around the current element a new parent container, something like that, but I don't like the following lines and I suppose that they are not really correct or best practice:
this.before('<div id="container">');
this.after('</div>');
// do something with the new parent here
$("#container")...
Is there a way more natural of doing this? Thank you.
You want to use the wrap function that is built for this!
this.wrap('<div id="container"></div>');
http://api.jquery.com/wrap/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With