jQuery .wrap(), anchors and IE

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 05:06:14

问题


I am trying to wrap an anchor-tag around a block of code using jQuery (v1.2.6) by doing the follwing:

var link = $('<a>').attr('href','http://www.foo.bar');
$('#block').wrap(link);

This works perfectly fine in all browsers but (you guessed it) the Internet Explorer (all versions I can use to test it). I do know from other cases that the IE is hella picky when you insert code via JavaScript, but in this case I just don't know what could be wrong with this simple anchor element? Anyone got an idea? Btw: I already tried generating the anchor via $('<a></a>') as suggested on several other posts unfortunately, makes no difference for me.

Thanks a whole lot!


回答1:


Updating my jQuery to 1.3+ did the trick.

Apparently var a = $('<a>'); in jQuery 1.2.6 and earlier will create a chunk of code that IE considers invalid and therefore will refuse to insert it into the DOM tree.



来源:https://stackoverflow.com/questions/6340374/jquery-wrap-anchors-and-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!