Using jQuery to wrap elements in a hyperlink

MultiDev

I have:

<div id="facebook">
    <span class="fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-facebook fa-stack-1x"></i></span><br /><span id="soc_fb"></span>
</div>

And on a certain action, I want to wrap the whole thing in a hyperlink like:

<div id="facebook">
    <a href="http://www.facebook.com"><span class="fa-stack fa-lg"><i class="fa fa-circle-thin fa-stack-2x"></i><i class="fa fa-facebook fa-stack-1x"></i></span><br /><span id="soc_fb"></span></a>
</div>

So, what I tried was:

$("#facebook").prepend('<a href="#" title="Facebook" class="facebook_c">').append('</a>');

But this does not seem to do anything. Any ideas?

Paul Roub

prepend() and append() add complete elements, not just start/end tags.

wrapAll() should do it:

$('#facebook').children().wrapAll('<a href="http://facebook.com"></a>');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using jQuery to wrap elements in a hyperlink

From Dev

Wrap groups of elements using jQuery

From Dev

Wrap groups of elements using jQuery

From Dev

Wrap string with hyperlink - jQuery & RegExp

From Dev

Wrap elements inside another using classes in jQuery

From Dev

Wrap around groups of elements using jQuery

From Dev

Wrap group of elements in multiple HTML elements using JQuery

From Dev

jQuery: Wrap elements with nextUntil()

From Dev

Wrap elements into div with jQuery

From Dev

Wrap tags around items inside existing <li> elements using jQuery

From Dev

Using jquery / javascript to wrap a series of HTML elements in Wordpress

From Dev

Reveal Div with Hyperlink using jQuery

From Dev

Jquery wrap elements inside div

From Dev

Wrap function Jquery for multiple elements

From Dev

How to wrap all HTML elements in a DIV depending on total height of those HTML elements using jQuery?

From Dev

wrap $ in span using jQuery

From Dev

Wrap hyperlink in td with same hyperlink

From Java

How to change the href for a hyperlink using jQuery

From Dev

How to create an image hyperlink element using jQuery?

From Dev

How to add a hyperlink dynamically using jQuery?

From Dev

How to add a hyperlink column to a table using jquery?

From Dev

How to wrap groups of two elements in jQuery?

From Dev

How to wrap elements in a group of items with jQuery?

From Dev

jQuery wrap multiple elements independent of level

From Dev

Wrap div around 2 sequential elements in jQuery

From Dev

Wrap a div around every 2 elements in jQuery

From Dev

Wrap multiple selected elements with a div with jquery

From Dev

Is using a HTML Label to wrap elements semantic?

From Dev

Creating elements using jQuery

Related Related

HotTag

Archive