Javascript: access DOM elements without getElementById -


this question has answer here:

below sample code.

<body>     <div id="wrapper" class="access">         <form id="test">             <input id="password"></input>             <input type="submit"></input>         </form>       </div>     <script>         console.log(password);         alert(wrapper.classname);     </script> </body> 

the console log returns dom element id password. alert "alert".

it works in normal code well, e.g. var x = wrapper.classname;

surely not right? point of document.getelementbyid, $('#password') or goog.dom.getelement if works this? these functions legacy now?

it works in firefox, chrome , safari, incidentally.

this answer should give lot go on:

https://stackoverflow.com/a/6381766/944006

you shouldn't use these variables, , don't want depend on them working correctly across browsers.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -