javascript - Get input value without using getelementbyid -



javascript - Get input value without using getelementbyid -

this question has reply here:

do dom tree elements ids become global variables? 3 answers

i found javascript code below, works !

function a(){ alert(myinput.value); } <input type="text" value="that`s new me" id="myinput"/> <input type="button" onclick="javascript:a();"/>

what new me, ability reach , utilize input value, without using getelementbyid funcion.

is mutual utilize way of coding ? pros , cons of coding ?

tnx amitai

dom elements have id automatically added properties on window object, id variable name. that's why can utilize myinput.

it's new feature in html5 spec:

the html5 standard specifies window object must have property key value elem if...

there 1 dom element elem property id has value key. there 1 dom element elem property name has value key. elem's tag must 1 of: a, applet, area, embed, form, frame, frameset, iframe, img, object.

source

personally, i'd advice against using it, have "no" command on variable names way.

declare own variables, "get" elements yourself, way won't have worry x perchance beingness variable or not.

javascript

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -