[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

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.
0
taz8020
Asked:
taz8020
  • 3
  • 2
1 Solution
 
RobOwner (Aidellio)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

0
 
RobOwner (Aidellio)Commented:
this puts the result in another div: http://jsbin.com/fepil/2/edit

is this what you want?
0
 
leakim971PluritechnicianCommented:
Test page : http://jsfiddle.net/Lmqhpjn8/
$("#mainDivOrSVG").find("[id]").each(function() {
   $("#myAnotherDIV").append( this );     
})

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
taz8020Author 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

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now