HTML attributes are not accessed that way. The getAttribute method is used for that. Data attributes also have a more specialized special way that they are accessed, using the dataset object.
Here one HTML property has so many data attributes at the parent level. In my case, things are slightly different →
<select class="license_type" name="license_type" id="license_type">
<option value="license_one" data-one="59">Single Site License</option>
<option value="license_two" data-two="245">5 Site License</option>
<option value="license_three" data-three="1569">Developers License</option>
</select>
Options are child to select Parent should I set ID for each option separately or just setting an ID at parent select we can fetch all options data attributes. Please advise.
If you want JavaScript to be able to get the data attributes without knowing the names, the dataset gives you an object list, and you can use Object.keys() to get the keys in that dataset.
But cant complete get into this. Would it be possible if you can help me with some example in fetching such things specially keeping my example(codepen) in mind.
Well with your example, I would assign the select element to a local variable using the unique identifier as a reference, then get the options of that select element, and loop through each of those options getting the data fields, most likely using the reduce method to combine things together.
There is a curse of Knowledge(Not getting cynical, argumentative or stubborn, but on a lighter note):
When someone is Pro his/her reality and perception is quite different from the novice. Even the enlightened folks suffer from the curse of Knowledge - Not understanding where a novice or less enlightened is standing and experiencing things differently than him/her. Two different realities.
If I would have grasped everything and every bit that you have told me I would have started implementing. I hardly get 30% of what you told me.
Alternatively I was searching for some live example, but miserably failed. May be my search terms were not good enough.
The first main objective to work on is to be looping through the options in the select object.
To do that, you need to get the options of that select object.
To do that, you need to get the select html element.
So, first, get the select html element.
Then get the options of that select html element.
Then loop through those options, outputting them to console.log as a test that the loop is correctly working.