jquery - Repeating functions -
i seem repeat alot of functions when coding simple, there better way of doing this?
$('#bt1').click(function() { $('#txt1').show(); $(this).css("background-image", "url(site_images/08/btn_over.png)"); }); $('#bt2').click(function() { $('#txt2').show(); $(this).css("background-image", "url(site_images/08/btn_over.png)"); }); $('#bt3').click(function() { $('#txt3').show(); $(this).css("background-image", "url(site_images/08/btn_over.png)"); }); $('#bt4').click(function() { $('#txt4').show(); $(this).css("background-image", "url(site_images/08/btn_over.png)"); });
so i'm not repeating code?
give buttons class
, such btn
, , can like:-
$('.btn').click(function() { $('#' + this.id.replace('bt', 'txt')).show(); $(this).css("background-image", "url(site_images/08/btn_over.png)"); });
Comments
Post a Comment