HTML DOM Select Object Last Updated : 03 Oct, 2024 Comments Improve Suggest changes Like Article Like Report The Select object in HTML DOM is used to represent an HTML <select> element. It provides properties and methods to manipulate the <select> element and its associated <option> elements.Syntax:To create <select> element. document.createElement("SELECT")To access <select> element. document.getElementById("mySelect")Select Object Properties:autofocus: It is used to set or return the drop-down list automatically get focused when the page loads.disabled: It is used to set or return whether the drop-down list is disabled, or not.form: It returns the reference to the form that contains the drop-down list.length:It returns the number of <option> elements in a drop-down list.multiple: It is used to set or return whether more than one option can be selected from the drop-down list.name: It is used to set or return the value of the name attribute of a drop-down list.selectedIndex: It is used to set or return the index of selected option in a drop-down list.size: It is used to set or return the value of the size of a drop-down list.type: It returns the type of form element a drop-down list.value:It is used to set or return the value of selected option in a drop-down list.Select Object Methods:add(): It is used to add an option to a drop-down list.checkValidity(): It is used to check the validity of a drop-down list.remove(): It is used to remove an option from a drop-down list.Select Object Collections:options: It returns the collection of all the options in a drop-down list.Example 1: This example create the <select> element by using document.createElement() method. html <!DOCTYPE html> <html> <head> <title> HTML DOM Select Object </title> </head> <body> <h2> HTML DOM Select Object </h2> <p> Click on button to create select and option element </p> <button id="btn" onclick="myGeeks()"> Create Select Element </button> <!-- script to create select element --> <script> function myGeeks() { let sel = document.createElement("Select"); sel.setAttribute("id", "MySelect"); document.body.appendChild(sel); let opt = document.createElement("option"); opt.setAttribute("value", "Banana"); let nod = document.createTextNode("Banana"); opt.appendChild(nod); document.getElementById("MySelect").appendChild(opt); let opt1 = document.createElement("option"); opt1.setAttribute("value", "Apple"); let nod1 = document.createTextNode("Apple"); opt1.appendChild(nod1); document.getElementById("MySelect").appendChild(opt1); document.getElementById("btn").disabled=true; } </script> </body> </html> Output:create select elementExample 2: This example access the <select> element by using getElementById() method. html <!DOCTYPE html> <html> <head> <title> HTML DOM Select Object </title> </head> <body> <h2>HTML DOM Select Object</h2> <select id="GFG"> <option>JavaScript</option> <option>HTML</option> <option>CSS</option> <option>TypeScript</option> </select> <p> Click on button to get the number of option elements in dropdown. </p> <button onclick="myGeeks()"> Button </button> <p id="test"></p> <!-- script to count select element --> <script> function myGeeks() { let len = document.getElementById("GFG").length; document.getElementById("test").innerHTML = len; } </script> </body> </html> Output:access select elementSupported Browsers: The browser supported by DOM Select Object are listed below: OperaGoogle ChromeFirefoxApple Safari Comment More infoAdvertise with us S Shubrodeep Banerjee Follow Improve Article Tags : Web Technologies HTML HTML-DOM Similar Reads HTML DOM InputEvent The input event is fired when the user changes an element, the value of an element or <textarea> element. DOM InputEvent occurs when an element in the HTML document gets input from the user. InputEvent property: data: Returns the inserted characters.dataTransfer: Returns an object containing i 2 min read HTML | DOM Parameter Object The Parameter Object in HTML DOM is used to create and access the <param> element with in the object.Parameters for plugin embedded with an element is done by using the element. Syntax: It is used to access a <param> element.var x = document.getElementById("myParam");It is used to create 2 min read HTML | DOM Link Object HTML DOM Link Object is used to access HTML <link> element.Syntax: To Access a HTML element: document.getElementById("myLink"); To Create a New HTML element: document.createElement("LINK"); Property Values: ValueDescriptioncharsetIt assigns the character encoding of the linked documentcrossOri 2 min read HTML DOM Style quotes Property The Style quotes Property in HTML DOM is used to set/return the type of quotation marks for embedded quotations. This element can be accessed by using getElementById() method. Syntax: To get the property.object.style.quotesTo set the property.object.style.quotes = "none | string string string string 2 min read HTML DOM KeyboardEvent getModifierState() Method The KeyboardEvent getModifierState() method in HTML DOM is used to return whether a specified modifier key is pressed, or activated. The KeyboardEvent getModifierState() method returns true if the specified key is pressed, otherwise it returns false. The list of key which is pressed then Modifier ke 1 min read HTML | DOM KeyboardEvent location Property The KeyboardEvent location property is used for returning a number that indicates the location of a key on the keyboard or device. The KeyboardEvent location property can be used on the onkeydown and onkeyup events but not on onkeypress. The number returned by KeyboardEvent location property is repr 2 min read HTML DOM Option label Property The HTML DOM Option label property is used to get or set the label attribute of an <option> element in a drop-down list (<select> element). The label property represents the text label associated with the option, which is shown in the drop-down list.Syntax: It is used to return the label 2 min read HTML DOM | KeyboardEvent altKey Property The KeyboardEvent altKey property in HTML DOM is a read-only property and used to return the boolean value which indicates the alt key is pressed or not. It returns True if alt key is pressed otherwise return false. Syntax: event.altKey Below program illustrates the KeyboardEvent altkey property in 1 min read HTML | DOM Form target Property The DOM Form Target property is used to set or return the value of the target attribute of the form.The Target attribute is used to specify whether the submitted result will open in the current window, a new tab or on a new frame. Syntax: It is used to return the target property. formObject.target I 3 min read HTML | DOM KeyboardEvent shiftKey Property The KeyboardEvent shiftKey property in HTML DOM is a read-only property and used to return a Boolean value which indicates the SHIFT key is pressed or not. The KeyboardEvent shiftKey property returns true if the SHIFT key is pressed, otherwise returns false. Syntax: event.shiftKey Below program illu 1 min read Like