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

taz8020
taz8020 used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Owner (Aidellio)
Most Valuable Expert 2015
Commented:
http://jsbin.com/fepil/1/edit

$(function(){
	var ids = [];
	$('div').each(function(i,el){
		ids.push($(el).attr('id'));
	});
	console.dir(ids);
});

Open in new window

RobOwner (Aidellio)
Most Valuable Expert 2015

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

is this what you want?
leakim971Multitechnician
Top Expert 2014

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

Open in new window

Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

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
Top Expert 2014

Commented:
In my case, the element is moved so each one is removed from original...
RobOwner (Aidellio)
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial