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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -