jQuery:如何在div中的现有图像周围包裹<a> and </a>标签?

时间:2012-03-21 23:39:53

标签: jquery slideshow

我正在使用slidy.js在div中循环显示多个图像。

我的问题是:如何使用jQuery围绕div(其id为“imgFade”)中的每个图像包裹<a href="http://www.google.com"></a>

提前致谢!
亚当

4 个答案:

答案 0 :(得分:6)

$('#imgFade img').wrap('<a href="http://www.google.com" />');

答案 1 :(得分:2)

是的,您可以使用.wrap()

示例:

$("#yourdiv img").wrap('<a href="http://www.google.com" />');
                      // Note: the self closing pattern ^ THIS is how you should define the wrapping element

这是用id="yourdiv"

包围div内所有图像的链接

答案 2 :(得分:1)

您可以使用jQuery的.wrap()方法:

$('div#imgFade img').wrap('<a href="http://www.google.com" />');

答案 3 :(得分:0)

jQuery docs(http://api.jquery.com/wrap/)似乎建议包括结束标记,其他所有答案都是自动关闭的。即:

$("#imgFade img").wrap("<a href='http://www.google.com'></a>");
相关问题