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 answersi 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...
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
Post a Comment