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

172
Vistas
click trigger() not working when page loads

I am trying to make a trigger work based on the query string of the URL I use this code to get URL string

var getUrlParameter = function getUrlParameter(sParam) {
  var sPageURL = window.location.search.substring(1),
    sURLVariables = sPageURL.split('&'),
    sParameterName,
    i;

  for (i = 0; i < sURLVariables.length; i++) {
    sParameterName = sURLVariables[i].split('=');

    if (sParameterName[0] === sParam) {
      return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
    }
  }
};

and once I get it I put it inside an if then else like so:

$(document).ready(function () {
  let code_para = getUrlParameter("code");

  if (code_para == "one") {
    $("#one").trigger('click');
  } else if(code_para == "two") {
    $("#two").trigger('click');
  } else if(code_para == "three") {
    $("#three").trigger('click');
  } else if(code_para == "four") {
    $("#four").trigger('click');
  } else if(code_para == "five") {
    $("#five").trigger('click');
  } else {
    //do nothing
  }
});

but the problem is the trigger part is not working I have attached a fiddle for the full code Fiddle

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

couple of suggestions - you could simplify your logic and simply use the code_para as the identifier on the selector (assuming that the code_para is actually the same as the id of the element you want to click. Not the else block remains to do something in the avbsence of code_para).

 $(document).ready(function () {
        let code_para = getUrlParameter("code");
       if (code_para)
       {
           $("#" + code_para).trigger('click');
       } else {
           //do nothing
       }
    });

But rather than triggering a click on another DOM element - I would trigger the function that the click causes - so if these items have a function on the click - then i would simply trigger the function directly - rather than stimulating a click event that then triggers the fucntion....

about 4 years ago · Juan Pablo Isaza Denunciar

0

Your issue is that clicking on #three (for example) does nothing (based on the provided fiddle).

So triggering the click, does nothing.

It's not (just) that it's too early, because the other bindings (hover and click) are on .box3, not #three. You need to trigger on .box3, eg:

$(()=> $(".box3").trigger('mouseover').trigger("click") )

So your (switch) would need to convert:

if (code_para == "one") {
    $(".box1").trigger('mouseover').trigger("click")
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