I have some code which uses a selector in a loop.
This works:
document.getElementById("new_grouping_"+i).value
This does not: $("#new_grouping_"+i).value
Is there a way to do this using jQuery?
You should use the val() function:
var myValue = $("#new_grouping_"+i).val(); // to get the value
$("#new_grouping_"+i).val("something"); // to set the value
$("#new_grouping_"+i).val() gets you the value of a form.
$("#new_grouping_"+i).text() gets you the text of an html element.
$("#new_grouping_"+i).html() gets you the html of an html element.
$("#new_grouping_"+i).val('value') sets the value of a form.
$("#new_grouping_"+i).text('value') sets the text of an html element.
$("#new_grouping_"+i).html('value') sets the html of an html element.
$("#new_grouping_"+i).append('value') prepends something at the beginning of an element
$("#new_grouping_"+i).append('value') appends something at end of an element
$("#new_grouping_"+i).before('value') places something before an element
$("#new_grouping_"+i).after('value') places something after an element.
See More: jQuery Manipulation