Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!