Hi Developers ,
Lets see How To Create List And Grid View Using JavaScript
Create an HTML file and the copy paste the below code in your file
<div id="container">
<center><h1>
How To Create List And Grid View Using JavaScript - ITSolutionsGuides
</h1><br>
<div class="buttons">
<button class="grid">Grid View</button>
<button class="list">List View</button>
</div></center>
<ul class="list">
<li style="background:lightgray">Item 1</li>
<li>Item 2</li>
<li style="background:lightgray">Item 3</li>
<li >Item 4</li>
<li style="background:lightgray">Item 5</li>
<li>Item 6</li>
</ul>
</div>
Now, add some CSS for list view and grid view.
h1 {font-size:22px; margin-top:20px;}
.grid, .list {padding:15px;}
#container ul { list-style: none; }
#container .buttons { margin-bottom: 20px; }
#container .list li { width: 100%; border-bottom: 1px; margin-top:5px; margin-bottom: 5px; padding: 5px; }
#container .grid li { float: left; width: 20%; height: 50px; border: 1px solid #CCC; padding: 20px; }
Lets Add some JavaScript
$('button').on('click',function(e) {
if ($(this).hasClass('grid')) {
$('#container ul').removeClass('list').addClass('grid');
}
else if($(this).hasClass('list')) {
$('#container ul').removeClass('grid').addClass('list');
}
});
We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides