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

101
Views
how to improve jquery javascript elements with equivalent id?

i have 5 modules with big equal js code, but only INT ID is different.

How to simple access to get one-style javascript jquery for all modules with dynamical id? ok 3 int is num. CODE eg:

$("#super_mod_519").find('form');
$("#super_mod_345").find('form');
$("#super_mod_430").find('form');
$("#super_mod_632").find('form');
$("#super_mod_234").find('form');
$("#super_mod_713").find('form');

$("#super_mod_519 .button input").val('');
$("#super_mod_345 .button input").val('');
$("#super_mod_430 .button input").val('');
$("#super_mod_234 .button input").val('');
$("#super_mod_632 .button input").val('');
$("#super_mod_713 .button input").val('');
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If the ids are the key elements here then you could collect them in an array and simplify things this way:

const ids=[519,340,430,632,234,713];

ids.forEach(id=>
  $(`#super_mod_${id} form`) // some action ...
);

ids.forEach(id=>
  $(`#super_mod_${id} .button input`).val('')
);

(In order for the above snippet to work we still need some HTML and jQuery of course.)

If you want to perform the jQuery-based operations at the same time you can of course run them both in the same ids.forEach() loop.

about 4 years ago · Juan Pablo Isaza Report

0

The jQuery selector below will select all elements that start with an id of "super_mod_".

$("*[id^='super_mod_']").find('form');
$("*[id^='super_mod_'] .button input").val('');
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!