I do not have much knowledge of jQuery, I would like to know how to get the selected
attribute of the dropdownlist using jQuery?
I do not have much knowledge of jQuery, I would like to know how to get the selected
attribute of the dropdownlist using jQuery?
With native JS you have to find out the option
that is selected. You can get this information through select.selectedIndex
, which indicates the index of the options of a selected dice that is selected.
To find and de-select you can do this:
var select = document.querySelector('select');
options = select.querySelectorAll('option');
options[select.selectedIndex].removeAttribute("selected");
jsFiddle: link
jQuery saves a few lines and lets you do this:
$('option:selected').removeAttr('selected');
jsFiddle: link
Making $('select').val('');
visually changes the state but the attribute is still there.