List/Grid View Switcher with jQuery

Category: Layout | October 27, 2019
Author: ajaypatelaj
Official Page: Go to Website
Last Update:August 1, 2023

Learn how to create a list/Grid view switcher with jQuery to switch the post/products. The plugin base on the jquery toggle on-click event buttons.

The plugin comes with nice and clean layout. The layout design developed by using the bootstrap framework. So if you are working with bootstrap or want to integrate this plugin, you can easily do that.

By default, the posts will be listed as a grid and when the user clicks on the list toggle button, the layout of the post will be converted into the list.

Similar when the user clicks on the Grid button the post layout revert back to a Grid layout. It’s a simple plugin that allows you to quickly implement the toggle functionality.

How to Use List/Grid View Switcher

Let’s load the all required files into the document. Because the plugin base on the bootstrap frame so you also need to load the framework files.

<!--CSS Reset-->
<link rel="stylesheet" href="">
<!--Bootstrap CSS-->
<link rel='stylesheet' href=''>

<script src=''></script>

<!--Bootstrap JS-->
<script src=''></script>

Our next step to add the CSS and Javascript files for list and grid view switcher.

<!--CSS for List/Grid View Switcher-->
<link rel="stylesheet" href="css/style.css">

<!--jQuery for List/Grid View Switcher-->
<script  src="js/script.js"></script>

The Markup

After that, we will create the markup. Let’s first create the two buttons that will be used to witch the list/grid view. We will simply create a div and place the two-button with a unique ID.

<div class="well well-sm">
    <div class="btn-group">
        <a href="#" id="list" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-th-list"></span>List</a> 
        <a href="#" id="grid" class="btn btn-default btn-sm"><spanclass="glyphicon glyphicon-th"></span>Grid</a>

Finally, we will define the container and write the HTML code for list of posts. The following code is only for a single post/product but you can simply copy & paste and create unlimited posts.

Ofcourewse, if you are working on a dynamic website then you can need to call the loop query.

<div class="container">
<div id="products" class="row list-group">
    <div class="item  col-xs-4 col-lg-4">
        <div class="thumbnail">
            <img class="group list-group-image" src="" alt="" />
            <div class="caption">
                <h4 class="group inner list-group-item-heading">
                    Product title</h4>
                <p class="group inner list-group-item-text">
                    Product description... Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
                    sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p>
                <div class="row">
                    <div class="col-xs-12 col-md-6">
                        <p class="lead">
                    <div class="col-xs-12 col-md-6">
                        <a class="btn btn-success" href="#1">Add to cart</a>

That’s It. You can customize it as you want.  Hope you like it.