I want to wrap a link which is in a div:

This :

<div id="hello">

http://google.fr/646564897564/8977748946

</div>

will be:

<div id="hello">
<div id="wrap">
http://google.fr/646564897564/8977748946
</div>
</div>

Thank you so much for your help

2 Answers

3
BeNdErR On Best Solutions

have a look here: http://jsfiddle.net/R44pn/

JS

var outer = document.getElementById("hello");
outer.innerHTML = "<div id='wrap'>"+outer.innerHTML+"</div>"

OUTPUT

<div id="hello">
    <div id="wrap">
        http://google.fr/646564897564/8977748946
    </div>
</div>

with JQuery

$("#hello").html("<div id='wrap'>"+$("#hello").html()+"</div>")

fiddle here: http://jsfiddle.net/q27Sw/

hope it helps

3
Alvaro On

Making use of jQuery you can use the wrapInner function:

var outer = $("#hello");
outer.wrapInner('<div id="wrap">);

http://jsfiddle.net/R44pn/6/