1
I have a simple question:
Why mine alert
does not display the attribute value name
button? Strangely if I insert javascript code after tag <button>
the alert works normally. Follow the code that does not work:
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
var x = document.getElementById('a').name;
function aoba() {
alert(x);
};
</script>
<body>
<button id="a" value="b" onClick="aoba()" name="botão"> BOTÃO 1 </button>
</body>
</html>
You can [Edit] the HTML question that we help to format. As it is hard to read the code...
– Sergio
If you put that
var x = document.getElementById('a').name;
at the end of the body, or this whole Javascript insidewindow.onload = function(){ ... }
that would have worked– Sergio
Thanks for the help, I think I understand how the DOM charging mode works.
– Daniel De Santana Sforzim
Great. If you want you can mark one of the answers as accepted. See you soon.
– Sergio
@Danieldesantanasforzim, If any answer solved your problem, you can click on V next to the answer and mark your question as answered.
– Brumazzi DB