Avatar of taz8020
taz8020
Flag 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.
jQueryJavaScript.NET Programming

Avatar of undefined
Last Comment
Rob

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Rob

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Rob

this puts the result in another div: http://jsbin.com/fepil/2/edit

is this what you want?
leakim971

Test page : http://jsfiddle.net/Lmqhpjn8/
$("#mainDivOrSVG").find("[id]").each(function() {
   $("#myAnotherDIV").append( this );     
})

Open in new window

taz8020

ASKER
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) {
                    svginsert.removeChild
                    while (svginsert.firstChild) {
                        svginsert.removeChild(print.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="#' + this.id + '"/>');
                      });

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
leakim971

In my case, the element is moved so each one is removed from original...
Rob

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:

http://jsbin.com/tisohu/1/

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