X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Option defaultSelected Property

Option Object Reference Option Object

Example

Check if the selected option is checked by default:

var x = document.getElementById("mySelect").selectedIndex;
var y = document.getElementsByTagName("option");
alert("Is " + y[x].text + " selected by default? " + y[x].defaultSelected);

Try it yourself »


Definition and Usage

The defaultSelected property returns the default value of the selected attribute.

This property returns true if an option is selected by default, otherwise it returns false.

Note: If an option is selected by default, it is displayed first in the drop-down list.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The defaultSelected property is supported in all major browsers.


Syntax

optionObject.defaultSelected

Technical Details

Return Value: A Boolean, returns true if the option is selected by default, otherwise it returns false


Option Object Reference Option Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook