Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Eventos de JavaScript en HTML5

New Here ,
Apr 07, 2021 Apr 07, 2021

Buen día,

Cuando uso el evento getElementsByTagName no me esta ejecutando la instruccion:

document.getElementsByTagName("img")[0].onclick=tipoflor;

Donde:
función tipoflor(){
 alerta ("pensamientos");

}

Tampoco window.onload=daTipoFlor;

------------------------------------ Codigo ------------------------------------------
.
.
.

<title>Documento sin título</title>

<script>

función
tipoflor(){
alert("pensamientos");

}
función daTipoFlor(){
document.getElementsByTagName("img")[0].onclick=tipoflor;
}
window.onload=daTipoFlor;
</script>

</head>

<body> <p><img src="imagenes2/flor01.jpg"></p>

</body>
</html>

---------------------------------------------------------------------------------------

 

144
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 07, 2021 Apr 07, 2021
LATEST

 

At a guess this may be what you are looking for:

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Onclick Function</title>
</head>
<body>

<p><img src="images2/flor01.jpg"></p>

<script>
function typeflor() {
alert("thoughts");
}

function daTypeFlor() {
document.getElementsByTagName("img")[0].onclick = function() {
// call the typeflor() function when image is clicked
typeflor();
}
}

// run the daTypeFlor() function on window load
window.onload = function() {
daTypeFlor();
};
</script>
	
</body>
</html>

 

 

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines