performance - Extract Substring from jQuery Selector -


i know popular topic , i've read other articles on substring selection in jquery, can't figure out how specific example working more efficiency , advice appreciated.

i have following code:

$('#plan-gallery').click(function(){     $('#gallery').addclass('active-slide')      $('#gallery').fadein()  });  $('#plan-ensuite').click(function(){     $('#ensuite').addclass('active-slide')      $('#ensuite').fadein()  });  $('#plan-bedroom').click(function(){     $('#bedroom').addclass('active-slide') /* code line redundant */     $('#bedroom').fadein() /* code line redundant */ }); 

this kind of code repeated many times throughout script.js , i'd rid of it's redundancy.

can jquery wizards make code better?

thanks in advance

assuming id of slide starts after first - in slide button id:

$('#plan-gallery,#plan-ensuite,#plan-bedroom').click(function(){    $('#' + this.id.substring(this.id.indexof('-') + 1)).addclass('active-slide').fadein(); }); 

Comments