We help IT Professionals succeed at work.

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

291 Views
Last Modified: 2014-09-25
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.
Comment
Watch Question

Owner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

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

is this what you want?
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

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

Open in new window

Author

Commented:
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

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
In my case, the element is moved so each one is removed from original...
RobOwner (Aidellio)
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:
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
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.