This is my HTML:
<select>
<option value="val1">Text1</option>
<option value="val2">Text2</option>
<option value="val3">Text3</option>
<option value="val4">Text4</option>
</select>
It is being dynamically populated via $.ajax()
I need to make a function that will place "val"
in key
and Text
in "value
" in the sessionStorage
, as the object reference. How can I achieve this?
How would it be iterated via index
?
My try:
document.getElementsByClassName('next')[0].addEventListener('click', function() {
sessionStorage.setItem(option.value, option.innerText);
});
.addEventListener()
is not firing at all . . . why?
Also, I need it loaded afterwards. How do I do it? Do I use .trigger()
?
Just like this:
This code won't work, here in the Stack Overflow snippet environment, but you can see it work here.