-3
That’s what I tried to do, but keeps showing up:
class 46 of the javascript course
null
Word not found
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title> Match - Procura elemento </title>
<script>
function carrega(){
var texto = document.getElementById("txt").innerHTML;
var res = texto.match("html");
document.write(texto+"</br></br>");
document.write(res+"</br>");
if(res == null){
document.write("Palavra não encontrada");
}else{
document.write("Encontrou: "+res.length+" Palavra");
}
}
window.addEventListener("load",carrega);
</script>
</head>
<body>
<p id="txt">aula 46 do curso de javascript</p>
</body>
</html>
The Result has to be :
class 46 of the javascript course
Word not found
Thank you, gave the result I wanted.
– Deregue pinto
But I just don’t quite understand what that means : if (res) Document.write(res + "</br>");
– Deregue pinto
Dei um complementada @Dereguepinto is a feature of
Javascript
this type of comparison in results that may comenull
.– novic