Fragmented Development

jQuery, wrap(), and IE

jacob | 29 December, 2009 15:32

I decided to create a collapsible/expandable navigation script as one of my first forays into jQuery, and ran into an interesting issue with the way I was using the wrap() function, and the way Internet Explorer interpreted it.

I was adding some anchor tags via wrap(), like so:

$('#selector').wrap('<a href="#">');

This worked fine in every browser I tested in, as long as it wasn't made in Redmond. The code ran fine, without any errors, but wrap() never added the anchors. This really stumped me for a while, since it not only broke in IE6, but 7 & 8 as well.

A quick change to the code, however, had everything working everywhere:

$('#selector').wrap('<a href="#"></a>');

Who knew IE was a stickler for properly formatted code? I'm not sure why this happens, but hopefully my discovery will save you some time in the future.

Comments

Re: jQuery, wrap(), and IE

jezra | 01/01/2010, 17:39

That does seem quite odd. Was the failure in the javascript or was it in the rendering on screen?

Add comment

All content, graphics and, design © 2005 - 2008 Fragmented Development. All rights reserved, may contain peanuts. Powered by LifeType.

Admin