我得到這個HTML代碼:獲取父DIV ID,並適用於元素
<div class="gallery" id="gallery_x">
<p>
<a href="http://a-dynamic-link.com">image1</a>
<a href="http://another-dynamic-link-com">image2</a>
</p>
</div>
(X =變量個數)
,我需要從DIV名爲.gallery得到ID,並將其應用到「一」 作爲一個相對就像這樣:
<div class="gallery" id="gallery_x">
<p>
<a rel="gallery_x" href="http://a-dynamic-link.com">image1</a>
<a rel="gallery_x" href="http://another-dynamic-link-com">image2</a>
</p>
</div>
我(不工作)解決方案迄今:
$(".gallery a").parents(".gallery").attr("rel", $(this).attr("id"));
如果有人能幫助我,我會很高興。
謝謝。
迪
這正是我需要的,謝謝! – dee