Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Jquery switch view modes without refresh Re: [Solved] Jquery switch view modes without refresh

#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();
});
});