简体   繁体   中英

JQuery .insertAfter() DOM elements

I have a HTML Table which in which i want to manipulate using JQuery

Table:

<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&amp;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&amp;FolderCTID=0x01200">Value 4</A>
</TD></TR>

........and so on 

</Table>

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".

I want to insertBefore the each element in the row to the corresponding element in the same row

I am using following code:

$('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...

Please help me on this

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"]'));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM