<div id="last"></div>
<p id="text">text</p>
<a id="link" href="xxx">link</a>
Suppose I have the code above, how can I wrap a <div></div> to the a element, and insert it after div element, the result should be:
<div id="last"></div>
<div><a id="link" href="xxx">link</a></div>
<p id="text">text</p>
Tried the code below, but not works
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.4.js"></script>
</head>
<body>
<div id="last"></div>
<p id="text">text</p>
<a id="link" href="xxx">link</a>
<script>
$('#link').wrap('<div></div>').detach().insertAfter('#last');
</script>
</body>
</html>
Thanks you
Should look like:
Example: http://www.jsfiddle.net/4yUqL/2/
Ref.: .wrap()