2012-03-21 22 views

回答

6

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

+0

請參閱http://api.jquery.com/wrap/ – 2012-03-21 23:43:06

+0

非常感謝!奇蹟般有效 :) – lith0pedion 2012-03-22 00:02:10

1

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

$('div#imgFade img').wrap('<a href="http://www.google.com" />'); 
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 

這是WRA p圍繞div內的所有圖像的鏈接id="yourdiv"

0

jQuery文檔(http://api.jquery.com/wrap/)似乎建議包括結束標記,其中所有其他答案都是自閉的。即:

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