I am not a Javascript guru as I am doing more server side work, so I struggle with this. I found pieces of how to do this. Basically, I have a number of elements that have identifiers starting with the string "tagRow_", and I need to return a list of all the actual identifiers of the elements, since I need not only the element, but also the identifier of the element, since I need to analyze a unique end for each on the server side to determine what matches it.
I found the code below to get all the elements, but I'm not sure if it returns to the list, or that if anyone can offer advice on how to return only a list of string identifier names, I would appreciate it. Thanks
EDIT: I really need to do this with a radio input field, by mistake I put a DIV in my own example. It works fine for a DIV, but does not work properly for a radio input, as shown 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/
source
share