0

I have a javascript variable (selectCategory) that contains an object. When I console log the object I get the below output:

0: <input id="radio-2087915-2" class="input_category" type="radio" name="2087915" value="Food" checked="checked">
​
context: <input id="radio-2087915-2" class="input_category" type="radio" name="2087915" value="Food" checked="checked">
​
length: 1

I'm trying to get the name value from the object but whatever I try, for example: var name = selectCategory.name; results in a null value.

This is probably super basic but how can I get this value into a variable?

user1419810
  • 836
  • 1
  • 16
  • 29
  • It looks like your object has a property called `"0"` (which is a valid property name) and that that property refers to a DOM element. So: `var name = selectCategory[0].name`. (Actually, it looks like a jQuery object. If it is, the previous example would work, but you could also do `var name = selectCategory.attr("name")`, which would be more idiomatic using jQuery.) – T.J. Crowder Apr 09 '19 at 15:30
  • Brilliant, thanks var name = selectCategory.attr("name") did the trick, have learnt something new today!! – user1419810 Apr 09 '19 at 15:31

0 Answers0