Skip to content Skip to sidebar Skip to footer

Wrapall() Only Working On The First Element?

I'm using this script to wrap two divs: jQuery: $('#wrapcb').click(function(){ $('#cboxOverlay, #colorbox').wrapAll('
'); }); HTML: &l

Solution 1:

That's because you've given them all the same ID (never use the same ID twice on a page). Change it to class or give each link a unique ID.

Here's an example using a common class on the links:

jQuery:

$(".wrapcb").click(function(){
  $('#cboxOverlay, #colorbox').wrapAll('<div class="wrapcolorbox">');
});

HTML:

<span><aclass="wrapcb"href="http://www.example.com/one">First link</a></span><span><aclass="wrapcb"href="http://www.example.com/two">Second link</a></span><span><aclass="wrapcb"href="http://www.example.com/three">Third link</a></span>

Post a Comment for "Wrapall() Only Working On The First Element?"