Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
onclick running when page loads

I have some code in javascript that I just want the object to change when I click on it, but it runs the code as if I have already clicked on the object as soon as the page loads

"use strict";

function changeText(obj){
    obj.innerHTML = "DON'T CLICK ME!";
}

function init(){
    var obj = document.getElementById("xPhoto");
    obj.onclick = changeText(obj);
}

window.onload = init;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are calling the changeText function in init so you are setting obj.innerHTML = "DON'T CLICK ME!" on init

Based on your description, you want to assign the chagneText to the onclick of obj, something like: obj.onclick = changeText

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda