When I alerted the type of a select element in JavaScript it displayed 'select-one'. But I thought it would display an empty string.
alert(document.getElementById('catsel').type)
// where catsel is a select box. it displayed select-one
I tested this in Firefox 3.0.0.10
Is it a cross browser value? I have never used this property until now. I just want to know whether the value select-one is the same in all browsers.
Besides I am using jQuery in my page. When I searched throughout the project for the string "select-one" matches were found in jquery.js. So I conclude that when the page had loaded jQuery is setting a property 'type' to the select elements. Am I right?
The <select> element is used to create a drop-down list. The <select> element is most often used in a form, to collect user input. The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the drop-down list will be submitted).
What is the use of html() method in jQuery ? The html() method in jQuery is used to get the contents of the first element in the set of matched elements or is used to set the HTML contents of every matched element. It returns the content of the first matched element. This function does not accept any arguments.
jQuery select() MethodThe select event occurs when a text is selected (marked) in a text area or a text field. The select() method triggers the select event, or attaches a function to run when a select event occurs.
The <select> element allows you to select one or multiple options. Add the multiple attribute to the <select> element to enable multiple selections. The HTMLSelectElement represents the <select> element. Use the selectedIndex and value to get the index and value of the selected option.
The type
property is actually a DOM property native to form input elements, and doesn't have anything to do with jQuery - you can quickly corroborate this by running this on any website:
console.log(document.createElement('select').type);
For select
elements, the two possible values it could take is select-one
for normal select elements, ad select-multiple
when more than one value is accepted (ie. when a valid multiple
attribute is set).
The value should be cross-browser compatible - I could not find any information disputing this.
Reference: https://developer.mozilla.org/en/DOM/select.type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With