jQuery selector of name attribute for different element types
jquery, jquery-selectors
Solution
All you need is an attribute selector:
$("[name='MaterialValue']")
Also, you are missing closing quotes after your attribute `name` in your html
Look here for reference: http://api.jquery.com/attribute-equals-selector/
Problem
I have a table of rows. In one of the columns, some rows have a span with static text, some rows have a select with values to choose from. All elements in that one column have the same name attribute. In my form submit, I iterate thru the rows and want to get the values for all columns. I would prefer to have one jQuery selector statement to get the value from that element (span or select with name attribute of "materialValue"). How would I do that with jQuery? Here follows the html snippet. ``` <table> <tr><td> <span id="materialValue1" name="materialValue>ONE</span> </td></tr> <tr><td> <span id="materialValue2" name="materialValue>TWO</span> </td></tr> <tr><td> <select id="materialValue3" name="materialValue> <option>ONE</option> <option>TWO</option> <option>THREE</option> </select> </td></tr> <tr><td> <select id="materialValue4" name="materialValue> <option>ONE</option> <option>TWO</option> <option>THREE</option> </select> </td></tr> </table> ``` Edit: I'm used to specifying the element type then square brackets with the attribute name/value. I'm not sure how to specify the jquery selector without the element type name. e.g. `$('span[name="materialValue"]', this)`. Is it legal to specify `$('[name="materialValue"]', this)`? looks weird to me.