Home › Forums › JavaScript › [Solved] Jquery switch view modes without refresh › Re: [Solved] Jquery switch view modes without refresh
January 25, 2011 at 10:23 am
#81182
jamygolden
Member
Yeah you can, that would be something like this:
Toggle Grid
Toggle List
// grid wordpress loop here
// list wordpress loop here
jQuery:
$(document).ready(function(){
$('a.toggle').click(function(){
$('#' + $(this).attr('id').substring(7)).toggle();
});
});
jQuery explanation:
If you click an anchor link with the class of toggle, take it’s ID, remove the first 7 characters (the first 7 are ‘toggle-‘). Toggle an ID of this new found value.
It could be more simple if you’d prefer:
$(document).ready(function(){
$('#toggle-grid').click(function(){
$('#grid').toggle();
});
$('#toggle-list').click(function(){
$('#list').toggle();
});
});