2013-03-10 48 views
0
的標籤重新放置

我一直在試圖重新定位現有的CMS製作HTML內的img標籤在DOM使用jQuery

<div class="catItemView groupLeading _inspirations"> 
<!-- (2) and place it here --> 
<div class="catItemHeader"> 
    <h3 class="catItemTitle"> 
     <a href="some link here">ways of seeing</a> 
     </h3> 
</div> 
<div class="catItemBody"> 
    <div class="catItemIntroText"> 
     <p> 
      <a href="youtube link here"> 
       <img alt="" src="image_link.jpg" /><!-- (1) would like to grab this--> 
       John Berger - ways of seeing 
      </a> 
     </p> 
    </div> 
    </div> 
<div class="catItemLinks"> 
</div> 
</div>  

我嘗試這樣做:

$('div.catItemIntroText img').prepend('div.catItemHeader'); 

但它只是混淆了所有其他的「框架」,並將所有圖像填充到「框架」(如這個框架)。 在此先感謝!

回答

0

此刻,您正在將圖像預設爲div。這將圖像預先考慮到div:

$('.catItemView').prepend($('.catItemIntroText img')); 

如果你有這樣的結構比,雖然一度在頁面上更多的,你會想這樣做是爲了得到期望的結果,每發生:

$('.catItemIntroText img').each(function() { 
    $(this).parents('.catItemView').prepend($(this)); 
}); 
+0

感謝,基本上第二個選項更合適,但它沒有解決這個問題。 想到它,也許它會更適合搜索每個'div.catItemHeader',並從那個位置抓取並替換'img'標籤 – 2013-03-10 11:31:21

+0

我已經編輯了我的代碼,我試圖預先添加到錯誤的選擇器,我已經把正確的一個放在了現在。 – 2013-03-10 11:35:48

+0

非常感謝你:) – 2013-03-10 11:38:20