Mathieu
Mathieu

Reputation: 761

Wrap a link which is in a specific div

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>

Upvotes: 0

Views: 62

Answers (2)

Alvaro
Alvaro

Reputation: 41605

Making use of jQuery you can use the wrapInner function:

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

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

Upvotes: 3

BeNdErR
BeNdErR

Reputation: 17927

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

Upvotes: 3

Related Questions