2017-08-26 163 views
0

我想從A標籤選擇與jquery br標籤幷包裝它。使用jquery包裝多個選定的元素與div divc與

我是第三方開發者開發的Chrome擴展程序,我得到這個數據的工作與:

<div id="indiv" style="font-size: 12px"> 
    <a href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
    <br> 

    <a href="/?side=profiles&id=39818"><span style="color: #800909">Ernest Ferdinand Solis</span></a> (21:09): content here 
    <br> 

    <a href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
    <br> 

    <a href="/?side=profiles&id=39818"><span style="color: #800909">Ernest Ferdinand Solis</span></a> (21:09): content here 
    <br> 
</div> 

正如你看到的,每一個「後」是單獨用在第一和BR末。

我已經將我應該如何平衡的辦法,我測試過一些野生的東西一樣,沒有線索:

$("<div>").insertBefore("#indiv a"); 
$("</div>").insertAfter($("#indiv a").next().next()); 

jQuery的追加/ DIV之後自動股利..

如何我想它看起來像到底:

<div id="indiv" style="font-size: 12px"> 
    <div> 
     <a href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
     <br> 
    </div> 

    <div> 
     <a href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
     <br> 
    </div> 

    <div> 
     <a href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
     <br> 
    </div> 

    <div> 
     <a href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
     <br> 
    </div> 
</div> 

有希望嗎?

回答

0

剛剛從我的頭頂。 添加這兩個元素類內部。 使用jquery這樣的:

$('#indiv div a').addClass('inner') 

對於br,

或者手動添加。

<a class="inner" href="/?side=profiles&id=60438"><span style="color: #2498E0">Esmeralda Angelseye</span></a> (21:12): content here 
      <br class="inner"> 

並且將它們包裝起來。

$('.inner').wrapAll('<div></div>'); 
+0

是的,好的想法!它幾乎可以選擇所有內容,但是「可以在這裏找到」的部分確實沒有標籤。 –

+0

可以添加標籤嗎? – NemanjaD