I'm looking to do this with one line of code.
var a = '';
$('#MyDivs div').each(function (){a+=this.id+',';});
a = a.substring(0,a.length-1);// remove the last comma
I though something like this would do it, but to no avail. Am I on the right tracks??
$('#MyDivs div[id]').join(', ');
Here you go in one line:
var a = $('#MyDivs div[id]').map(function(){ return this.id }).get().join(', ');
Here's the fiddle: http://jsfiddle.net/tGFeZ/
This should offer some assistance: How to get all of the IDs with jQuery?
There is a one line example there, although it may not be the most attractive solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With