Why not use a class instead of an id in order to target all buttons? Or alternatively something like:
$('img[alt="button"]').hover( function () { $(this).fadeTo('fast', .10); }, function () { $(this).fadeTo('fast', 1.0); } ); Maurício -----Mensagem Original----- De: simon Para: jQuery (English) Enviada em: terça-feira, 9 de junho de 2009 07:56 Assunto: [jQuery] same effect on multiple objects with same id I basically have several buttons that are created dynamically via a db, so I can have 1 to 40 etc. now at the moment I give each one a unique id and a hover code in the loops. see below: loops goes here.. <img src="button.jpg" alt="button" border="0" id="myButton<?= $newCode ?>" /> $(document).ready(function(){ $("#myButton<?=$newCode ?>").hover( function () { $(this).fadeTo('fast', .50); }, function () { $(this).fadeTo('fast', 1.0); } ); }); end loop this works fine but gives me a lot of jquery code as well for each as i also have a click action after it, but thats another matter, what i am after is if i just give it the same id as below then i would like only to have one hover code that would do the effect to all, but at mo it will only do the effect to the first, any ideas? loops goes here.. <img src="button.jpg" alt="button" border="0" id="myButton"/> end loop So only this loops and i only need the code below once. $(document).ready(function(){ $("#myButton").hover( function () { $(this).fadeTo('fast', .50); }, function () { $(this).fadeTo('fast', 1.0); } ); }); Many thanks Si