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

114
Views
How to trigger onclick div using javascript

I want to trigger onclick of my div using click event in javascript. But I can be avble to trigger the onclick using jquery. Below is my code.

html += '<div id="add_redirect" class="row pl_filter_value margin-bottom-md ' + applied_class + '"onclick="applyFilter( \'' + filter.name + '\', \'category\', \'true\');"><div class="col-xs-12">In Stock Only' + applied_cross+ </div></div>';

$("document").ready(function() {
        setTimeout(function() {
            $("#add_redirect").trigger('click');
        },1);
    });

if I trigger by using document.getElementById('add_redirect').click(); the error is telling as Cannot read properties of null (reading 'click') .Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use addEventListener https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event

html += `
  <div id="add_redirect" class="row pl_filter_value margin-bottom-md + ' ' + ${applied_class}">
    <div class="col-xs-12">In Stock Only + ${applied_cross} </div>
  </div>
`;

$("document").ready(function() {
  const el = document.getElementById("add_redirect");
  el.addEventListener("click", () => {
    // handle onclick here
  });

  setTimeout(function() {
    el.click();
  }, 1);
});
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!