0
Javascript must be with event onmouseover
function mostrarID() {
.........................
.........................
}
document.onmouseover = mostrarID;
HTML example
O ID é:"<span id="span" style="font-weight:bold"></span>"<br>
<p id="p1">Paragrafo</p>
<div id="Div1">
<p id="p2">Paragrafo2</p>
<hr id="hr1">
<a href="#" id="Home">Home</a>
</div>
<p id="p3">Paragrafo3</p>
<a href="#" id="nav-questions">Perguntas</a>
<p id="p4">Paragrafo4</p>
<a href="#" id="Tags">Tags</a>
<div id="Div2">
<form id="Form">
<input id="Input" type="text"/>
</form>
</div>
Why does it only work if you put the script below html? I never understood it.
– user60252
Execution order in the browser. If placed before, the element
#span
will not exist in the GIFT whengetElementById("span")
is executed, keeping asnull
the variablespan
. Confirm this by accessing the browser console, the error probably appeared Cannot set Property 'innerHTML' of null .– Woss
Thanks Anderson Carlos Woss
– user60252
Perfect, I tested on all five browsers! I was using var elem = Document.elementFromPoint(Event.clientX, Event.clientY) Document.all.span.innerText = elem.id but firefox does not work.
– user60252