wrapAll()仅适用于第一个元素?
问题描述:
我使用这个脚本包两个div:wrapAll()仅适用于第一个元素?
的jQuery:
$("#wrapcb").click(function(){
$('#cboxOverlay, #colorbox').wrapAll('<div class="wrapcolorbox">');
});
HTML:
<span><a id="wrapcb" href="http://www.example.com/one">First link</a></span>
<span><a id="wrapcb" href="http://www.example.com/two">Second link</a></span>
<span><a id="wrapcb" href="http://www.example.com/three">Third link</a></span>
奇怪的是,这个脚本只在作品上第一个环节和其他所有人都被忽略。
任何想法我做错了什么?
答
这是因为你给他们所有相同的ID(never在页面上使用相同的ID两次)。将其更改为课程或为每个链接指定一个唯一的ID。
下面是使用上的链接一个共同的类的例子:
的jQuery:
$(".wrapcb").click(function(){
$('#cboxOverlay, #colorbox').wrapAll('<div class="wrapcolorbox">');
});
HTML:
<span><a class="wrapcb" href="http://www.example.com/one">First link</a></span>
<span><a class="wrapcb" href="http://www.example.com/two">Second link</a></span>
<span><a class="wrapcb" href="http://www.example.com/three">Third link</a></span>
感谢,做工精细现在:) – Kev89 2013-03-24 23:05:54