I cannot seem to find it. Thanks!
Example:
$("#MySelect").append(new Option("MyOption", "MyOption", true, true));
I cannot seem to find it. Thanks!
Example:
$("#MySelect").append(new Option("MyOption", "MyOption", true, true));
The Mozilla Dev Center is the de facto standard documentation site for all things JavaScript.
option
element reference:<option
> elementHTMLOptionElement
interface (which is implemented by the above)HTMLOptionElement
interface specSince you're using jQuery, however, there's a better way to construct elements.
$('#MySelect').append('<option></option>',
{
text: 'MyOption',
value: 'MyOption',
selected: true
})
I'm not sure what the last true
argument should do - at least in Chrome, new Option('text', 'value', true, true)
seems to return the same thing as new Option('text', 'value', true)
.
None of the current postings answers the question regarding getting "... Documentation for ALL of the Javascript HTML Element Constructors". The example is explicitly using the " ... new Option ..." constructor.
This "answer" provides references that do not define any constructors such as new Option()
.
The DOM reference provided, should have defined the Option()
constructor or at least alluded to it.
The programmed constructor Option()
is NOT HTML and so is NOT defined by the other two references which describe HTML. The tag element, <OPTION>
is an HTML defined token so presumably, by implicit precedent only, new Option()
is the corresponding equivalent constructor, absorbing <OPTION>
property attributions analogously to other dynamic constructs, but where is this formally, explicitly and emphatically stated to define new Option()
? In particular, the kind and order of new Option()
's parameters would be defined in such a document.
Though it's not a constructor proper, the createElement() document
method is well defined ( https://developer.mozilla.org/en/DOM/document.createElement ). Using document.createElement("option")
with the HTMLOptionElement
references in this "answer" completely defines such construction.
An archaic document that initiated a legacy of confused paradigms between the DOM, HTML and javascript does define new Option()
here but is inadequate in the contemporary context.
If you don't know / can't find that doc, You can try using the HTML if you know that.
$("#MySelect").append("<option value='myValue'>MyValue</option>");
or
$("#MySelect").append("<option value='myValue' selected>MyValue</option>");
The syntax you have looks like it might be jQuery - is it? If so, then append takes an HTML string. You don't have to create HTMLElement subclasses for it.
This reference from Mozilla will be helpful in understanding the HTML DOM elements.
This site provides javadoc style documentation on the HTMLElement class and its subclasses.
Not really documentation, but I've just published a short article with a list of HTMLElement subclasses. I might expand on it later on.
I've searched the web and couldn't find a list like this. Like I said, it's no documentation, but someone might find it useful having a list of all the subclasses in a single place.