Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery: click for every id-element starting with

I tried to find all ids starting with the string "matchItem_" and define a click-event for each. onclick i want wo execute a script with a URL parameter and change the image in this id-element. Unfortunately my syntax isn't right, I also tried with .each.function but I didn't get it.

$('[id^="matchItem_"]').each {
    
    $(this).click(){
     //...execute my script.php?urlparam=xx....;
     $(this).find('img').attr('src','/admin/images/ok.png');
    }

}
like image 876
michbeck Avatar asked Aug 08 '11 16:08

michbeck


1 Answers

You don't need the each:

$('[id^="matchItem_"]').click(function() {
   // do something
   $(this).find('img').attr('src','/admin/images/ok.png');
});
like image 61
Mrchief Avatar answered Sep 29 '22 14:09

Mrchief