1
I’m not so familiar with jQuery, I’d like to know how to get the attribute selected
dropdownlist using jQuery?
1
I’m not so familiar with jQuery, I’d like to know how to get the attribute selected
dropdownlist using jQuery?
1
With native JS you must discover the option
which is selected. You can obtain this information through select.selectedIndex
, which indicates which index of the options of a given select is selected.
To find and de-select you can do so:
var select = document.querySelector('select');
options = select.querySelectorAll('option');
options[select.selectedIndex].removeAttribute("selected");
jsFiddle: https://jsfiddle.net/L7b0hgLx/
jQuery saves some lines and lets you do so:
$('option:selected').removeAttr('selected');
jsFiddle: https://jsfiddle.net/L7b0hgLx/1
Making $('select').val('');
visually changes the state but the attribute is still there.
Browser other questions tagged javascript jquery html
You are not signed in. Login or sign up in order to post.