Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  113] [ 6]  / answers: 1 / hits: 20867  / 14 Years ago, thu, march 17, 2011, 12:00:00

I'm not a Javascript guru as I do more server-side work so am struggling with this. I have found bits and pieces of how to do this. Basically, I have a series of elements that have ids beginning with the string tagRow_ and I need to get back a list of all of the actual element ids as I need not just the element but also the element's id as I need to parse the unique ending for each on the server-side to determine what it corresponds to.



I found the code below to get all elements but am not sure what it is returning as far as a list or what, if anyone can offer advice how to return just a list of string id names I would appreciate it. Thanks



EDIT: I actually need to do this with a radio input field, it was by mistake I put a DIV in my own example. It works fine for a DIV but is not working properly for a radio input like below:



 <input id=tagRow_ddd type=radio value=h>
<input id=tagRow_ddd type=radio value=p>
<input id=tagRow_ddd type=radio value=r>
<input id=tagRow_ddd type=radio value=c>

$(input[id^='tagRow_']).each(function() {

var id = this.id,
idNumber = id.replace(/D+/, '');
document.body.innerHTML += idNumber + '<br />';
});


http://jsfiddle.net/fD7fP/3/


More From » jquery

 Answers
33

Live Demo



var elements = [];

$(div[id^='tagRow_']).each(function(){
elements.push(this.id);
});

var stringOfElementIDs = elements.toString();

[#93236] Wednesday, March 16, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
helenat

Total Points: 450
Total Questions: 95
Total Answers: 97

Location: Central African Republic
Member since Mon, Aug 10, 2020
4 Years ago
helenat questions
;