Give them a generic class that you can use to select them, and then use the first part of the identifier to create a selector for .show() .
jQuery('.someClass').click(function( event ) { event.preventDefault(); allTabs.hide(); jQuery('#' + this.id.split('-')[0] ).show();
Update:
Assuming the display is one of allTabs , I would do it instead.
jQuery('.someClass').click(function( event ) { event.preventDefault(); allTabs.hide().filter('#' + this.id.split('-')[0] ).show(); });
Avoid reselecting the DOM.
Also, instead:
'#' + this.id.split('-')[0]
... you could do this:
'#' + this.id.replace('-show','')
source share