script com addEventListener não tá funcionando :(
blza galera?
Sou iniciante em JS, to lendo um livro sobre o assunto e aos poucos vou treinando e fazendo alguns scripts simples pra praticar.
Me deparei com um script que não tá querendo funcionar, mesmo sendo tão simples...
Tenham paciencia hehehe
Queria que o script adicionasse a div de id='testando' um 'onclick' que disparasse a função alertar()...
só que não tá rolando! alguem me ajuda!!
valeu!
segue o script:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Event Listener</title>
<script type="text/javascript">evento = {
objeto:document.getElementById('testando'),
alertar:function()
{
alert(evento.objeto.firstChild.nodeValue);
},
adicionarEvento:function(){
evento.objeto.addEventListener('click',evento.alertar,false);
}
}
window.onload = evento.adicionarEvento;
</script>
</head>
<body>
<div id="testando">
testando!
</div>
</body>
</html>Discussão (1)
Carregando comentários...