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
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.
Alternatively, add class="sales_info" to your HTML mark-up.
Then, do this:
$(".sales_info").bind("click", function() {
...
}
You want the attribute starts with selector:
$('div[id^="sales_info"]').bind( ... );