Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML select element type is 'select-one' when jQuery is included. Is it a cross browser value?

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?

like image 893
Jach Many Avatar asked Jan 11 '11 07:01

Jach Many


People also ask

What is select element in HTML?

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).

How HTML elements are used in jQuery with example?

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.

What is select in jQuery?

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.

What is select element in Javascript?

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.


1 Answers

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

like image 103
Yi Jiang Avatar answered Oct 11 '22 16:10

Yi Jiang