I have a bunch of views: .view-1, .view-2, view-3, etc… I was using something hacky like this to get the right view showing when the right item in the navigation was clicked:
$(".contact a").click(function() {
$(".view-1").hide();
$(".view-2").hide();
$(".view-3").hide();
$(".view-4").hide();
$(".view-5").hide();
$(".view-6").show();
return false;
});
But this is difficult to maintain over a bunch of nav item and ever more views.
I’d like to do something like this:
var $allViews = $(".view-1,.view-2");
$(".how").click(function() {
$(allViews).hide();
$(".view-2").show();
return false;
});
Where I could assign all the view classes
How about :
var $allViews = $("[class|='view']")Gets all elements with classes equal to ‘view’ or starting with ‘view’ followed by a hyphen
Or:
var $allViews = $("[class^='view-']")Gets all elements with classes that start with ‘view-`
$allViews.hide()would hide all of those elements.Example here: http://jsfiddle.net/Af9M3/