JQuery .insertAfter()DOM元素 [英] JQuery .insertAfter() DOM elements
问题描述
我有一个HTML表格,我想在其中使用JQuery进行操作
I have a HTML Table which in which i want to manipulate using JQuery
表格:
<Table>
<TR>
<TD><div class=ExternalClass00FA6D5A488C4B2582667D6D8DF15F79>Value 1</div></TD>
<TD class="ms-disc-bordered-noleft">Value 2</TD>
<TD class="ms-disc-bordered-noleft">Value 3</TD>
<TD class="ms-disc-bordered-noleft">
<A HREF="/Threaded.aspx?RootFolder=%2fLists&FolderCTID=0x01200">Value 4</A>
</TD></TR>
...............
<TR>
<TD><div class=ExternalClass00FA6D5A488C4B2582667D6D8DF15F79>Value 1</div></TD>
<TD class="ms-disc-bordered-noleft">Value 2</TD>
<TD class="ms-disc-bordered-noleft">Value 3</TD>
<TD class="ms-disc-bordered-noleft">
<A HREF="/Threaded.aspx?RootFolder=%2fLists&FolderCTID=0x01200">Value 4</A>
</TD></TR>
........and so on
</Table>
我正在尝试在href中选择最后一个具有字符串"FolderCTID"的值4",并使用以"ExternalClass"开头的div类在值1"之前insertBefore.
i am trying to pick "Value 4" the last having string "FolderCTID" in href and insertBefore "Value 1" with div class that starts with "ExternalClass".
我要在行中的每个元素之前插入同一行中的相应元素
我正在使用以下代码:
$('a[href*="FolderCTID"]').insertBefore($('div[class^="ExternalClass"]'));
但是它正在为每一行插入所有元素....我想我应该做一些事情来指定实体并在实体的每一端循环...
But it is inserting all the elements for every row....i think i should make something to specify the entities and loop around each end of the entity...
请帮助我
推荐答案
您只需要在当前tr内查找ExternalClass,这样您就可以以此为起点:
you have to look for the ExternalClass only inside the current tr so you could do something like this as a startingpoint:
$.each($('a[href*="FolderCTID"]'), function() {
$(this).insertBefore($(this).parents('tr').find('div[class^="ExternalClass"]'));
});
这篇关于JQuery .insertAfter()DOM元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!