performance - JQuery Efficiency Need to make my Code Better and Learn -


i have below code , want know bad way right it. how accomplish same thing without having duplicate code each set of items. appreciated.

<script type="text/javascript"> $('#plink-1').click(function() {     $('.active').slideup().removeclass('active');     $('#pshow-1').slidetoggle().addclass('active'); }); $('#plink-2').click(function() {     $('.active').slideup().removeclass('active');     $('#pshow-2').slidetoggle().addclass('active'); }); $('#plink-3').click(function() {     $('.active').slideup().removeclass('active');     $('#pshow-3').slidetoggle().addclass('active'); }); $('#plink-4').click(function() {     $('.active').slideup().removeclass('active');     $('#pshow-4').slidetoggle().addclass('active'); }); 

$('#plink-1, #plink-2, #plink-3, #plink-4').click(function() {     var index = this.id.replace('plink-','');  // give ->  1,2,..     $('.active').slideup().removeclass('active');     $('#pshow-' + index).slidetoggle().addclass('active'); }); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -