0
I’m starting with javascript and I made the following code below, only it’s not working on google Chrome, why?
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Teste</title>
</head>
<body>
<form>
<input type="text" name="teste" id="teste"/>
</form>
</body>
<script type="text/javascript" src="test.js"></script>
</html>
test js.
var teste = document.getElementById("teste");
teste.addEventListener('click', function(){
alert(1);
});
I have tested it on Firefox and JS Bin site and it works perfectly.
Include in your script:
<script type="text/javascript" src="test.js" defer></script>
– MarceloBoni
Also include your tag
script
before closing the tagbody
and not later. Alias, which version of Chrome are you using? My version58.0.3029.110 (64-bit)
is working, I do not know if this has influence, but Chrome corrected the structure, automatically putting the tagscript
before the closure ofbody
.– Lucas Fontes Gaspareto
The younger one, this "Defer" is for what? but I think I know what happened, Chrome was caching the old code and not the new one.
– Thiago
defer
ensures that the script is only loaded after loading html, for very old versions of browsers, does not work– MarceloBoni
Tip: always use anonymity mode to do your tests, and it’s okay to use the script between tags
<body>
– MarceloBoni
Okay, thank you, is there a "developer mode" for testing cacheless scripts?
– Thiago
Anonymity
– MarceloBoni
I tested on Chrome and it worked smoothly - i.e. I can’t reproduce the problem.
– Daniel
@Henriqueoliveira, solved your problem? It was really cache?
– Aline