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

214
Views
jQuery match only part of id from div

I ran into an unusual situation yesterday night.

I need to match only part of id. Let me clear you all with an example

I have few divs like

<div id="sales_info_1">... ...... ...... ...... ...</div>
<div id="sales_info_2">... ...... ...... ...... ...</div>
<div id="sales_info_3">... ...... ...... ...... ...</div>

and jQuery goes like

jQuery("div#dont_know_what_to_write_here").bind("click", function(){
    ... ...... ...... ...... ...
});

I need to match only sales_info, ignoring _1, _2 or _anything, can anyone suggest me how to achieve this?

Thanks

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You could use the "Starts With" selector:

$('div[id^="sales_info_"]')

I'd rather recommend you use a unique class name for your elements that you can select on though.

over 4 years ago · Santiago Trujillo Report

0

Alternatively, add class="sales_info" to your HTML mark-up.

Then, do this:

$(".sales_info").bind("click", function() {
   ...
}
over 4 years ago · Santiago Trujillo Report

0

You want the attribute starts with selector:

$('div[id^="sales_info"]').bind( ... );
over 4 years ago · Santiago Trujillo 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!