Link to home
Start Free TrialLog in
Avatar of taz8020
taz8020Flag for United Kingdom of Great Britain and Northern Ireland

asked on

jquery loop through ids in a div and show names in another div

Hi I have a div and want to loop through each inner ID and then append the Id to another div using jquery.

well actually its a svg image but if you know how to do it with div I know it would work on a svg.
Avatar of Rob
Flag of Australia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this puts the result in another div:

is this what you want?
Test page :
$("#mainDivOrSVG").find("[id]").each(function() {
   $("#myAnotherDIV").append( this );     

Open in new window

Avatar of taz8020


how would I clear all the elements first, this is what I had

I use this to remove all elements in the id first
var svginsert = document.getElementById('svginsert');
                if ($('#svginsert').length > 0) {
                    while (svginsert.firstChild) {

Open in new window

then I was trying this to add them back in once changed
$('#svgwithIDs').each(function () {
                            svginsert.appendChild('<use xlink:href="#' + + '"/>');

Open in new window

In my case, the element is moved so each one is removed from original...
i did this with a table as an example for someone else but I'm just trying to gauge what you're trying to do:

This can be done easily enough with <div> elements too