我使用slidy.js在div內循環顯示幾張圖片。jQuery:如何將<a>和</a>標籤包裝在div中的現有圖像周圍?
我的問題是:我如何使用jQuery將<a href="http://www.google.com">
和</a>
圍繞div中的每個圖像(其ID是「imgFade」)?
在此先感謝!
亞當
我使用slidy.js在div內循環顯示幾張圖片。jQuery:如何將<a>和</a>標籤包裝在div中的現有圖像周圍?
我的問題是:我如何使用jQuery將<a href="http://www.google.com">
和</a>
圍繞div中的每個圖像(其ID是「imgFade」)?
在此先感謝!
亞當
$('#imgFade img').wrap('<a href="http://www.google.com" />');
您可以使用jQuery的.wrap()方法:
$('div#imgFade img').wrap('<a href="http://www.google.com" />');
是的,你可以使用.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"
jQuery文檔(http://api.jquery.com/wrap/)似乎建議包括結束標記,其中所有其他答案都是自閉的。即:
$("#imgFade img").wrap("<a href='http://www.google.com'></a>");
請參閱http://api.jquery.com/wrap/ – 2012-03-21 23:43:06
非常感謝!奇蹟般有效 :) – lith0pedion 2012-03-22 00:02:10