Mike Tavish Mike Tavish - 2 months ago 11
Javascript Question

Jquery: How add new parent to element

I trying to add new parent to child. i use this code

$("#span").before('<div class="newPaernt">');

this add div

<div class="newParent"></div><span id="span"></span>


<div class="newParent><span id="span"></span>


The purpose of before() method is inserting content before an element. For wrapping with an element use wrap() method.

$("#span").wrap('<div class="newPaernt">');

$("#span").wrap('<div class="newPaernt">');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="span">a</span>