Foundation CSS JavaScript
Last Updated :
22 Aug, 2022
A Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. The framework is based on bootstrap, which is similar to SaaS. It’s more complex, versatile, and configurable. It also comes with a command-line interface, making it simple to use with module bundlers. Email framework provides you with responsive HTML emails, which can be read on any device. Foundation for Apps allows you to build fully responsive web applications.
Foundation CSS JavaScript:
- Installing & Initialization: We can add Foundation CSS JavaScript by using NPM install and CDN link.
- Using Plugins: The Plugins are attached to HTML elements using data attributes. The data attribute will match the name of the plugin.
- Configuring Plugins: All the plugins have configuration settings that customize their work.
- Adding Plugins After Page Load: Any plugins won't be initialized by default if we want to add new HTML to DOM. Call the foundation() function to check for new plugins.
- Adding Content to Plugins: We have added a global reInit() method that will remove and reapply event listeners, and update the plugin's instance data for relevant information.
- Programmatic Use: Some plugins can be created programmatically in JavaScript as the plugin is a class on the Foundation object, with a constructor that accepts two parameters: an element and an object options.
- Events: Every plugin fires DOM events after functions finish.
CDN link: We can get the required foundation JS from CDN by just inserting the below lines of code in our HTML template:
<script src=”https://cdnjs.cloudflare.com/ajax/libs/foundation/6.0.1/js/vendor/jquery.min.js”></script>
<script src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/js/foundation.min.js” crossorigin=”anonymous”>
</script>
JavaScript Initialization: The .foundation() function on the jQuery object, can be utilized to avail every Foundation plugin at once.
Syntax:
$(document).foundation();
Some of the codes are given for reference, the developer can make use of other features as per the need.
Example 1: This example shows the significance of Foundation JS by implementing its initialization.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/foundation.min.css">
<!-- Compressed JavaScript -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/foundation.min.js">
</script>
<style>
body {
margin-left: 10px;
margin-right: 10px;
}
</style>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<h3>Foundation CSS JavaScript</h3>
<div id="divID">
<ul class="dropdown menu" data-dropdown-menu>
<li> <a href="#">Tutorials</a>
<ul class="menu">
<li>
<a href="#">Interview Corner</a>
</li>
<li>
<a href="#">Languages</a>
</li>
<li>
<a href="#">CS Subjects</a>
</li>
<li>
<a href="#">GATE</a>
</li>
</ul>
</li>
<li><a href="#">Student</a>
<ul class="menu">
<li>
<a href="#">Campus Ambassador Program</a>
</li>
<li>
<a href="#">Geek Of the Month</a>
</li>
<li>
<a href="#">Placement Course</a>
</li>
</ul>
</li>
<li><a href="#">Jobs</a>
<ul class="menu">
<li>
<a href="#">Apply for Jobs</a>
</li>
<li>
<a href="#">Post a Job</a>
</li>
</ul>
</li>
<li>
<a href="#">Courses</a>
</li>
</ul>
</div>
<script>
$(document).foundation();
</script>
</body>
</html>
Output:
Example 2: The following code demonstrates the Foundation CSS JavaScript using Plugins. We are using accordion by using data attributes namely "data-accordion", "data-accordion-item" and "data-tab-content".
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/foundation.min.css">
<!-- Compressed JavaScript -->
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/foundation.min.js">
</script>
<style>
body {
margin-left: 10px;
margin-right: 10px;
}
</style>
</head>
<body>
<h1 style="color:green">GeeksforGeeks</h1>
<h3>Foundation CSS JavaScript using Plugins</h3>
<div id="divID">
<ul class="accordion" data-accordion>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title">Accordion 1</a>
<div class="accordion-content" data-tab-content>
<p>This is the Content of Accordion 1</p>
</div>
</li>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title">Accordion 2</a>
<div class="accordion-content" data-tab-content>
<p>This is the Content of Accordion 2</p>
</div>
</li>
<li class="accordion-item" data-accordion-item>
<a href="#" class="accordion-title">Accordion 3</a>
<div class="accordion-content" data-tab-content>
<p>This is the Content of Accordion 3</p>
</div>
</li>
</ul>
</div>
<script>
$(document).foundation();
</script>
</body>
</html>
Output:
Reference: https://get.foundation/sites/docs/javascript.html
Similar Reads
Foundation CSS JavaScript Events
Foundation CSS JavaScript is a set of JavaScript tools and plugins that can be used to add interactivity and functionality to your website. It includes a variety of plugins for things like modals, alerts, and accordions, as well as utility functions for handling events and working with the DOM. Foun
3 min read
Foundation CSS JavaScript Utilities
Foundation JavaScript Utilities is a collection of tools that can be used to enhance the functionality of your Foundation website. To use Foundation JavaScript Utilities, you first need to include the foundation.js file in your website. Once you have done this, you can use the various utilities by c
4 min read
Foundation CSS Orbit
Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. The framework
4 min read
Foundation CSS JavaScript using Plugins
Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails to look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay, M
3 min read
Foundation CSS JavaScript Timer Utility
Foundation CSS is a responsive front-end framework for web development. It includes a variety of CSS and JavaScript utilities that can be used to build and style web applications. One of the JavaScript utilities included in Foundation is a timer utility, which can be used to execute a function after
3 min read
Foundation CSS Switch
Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Moz
5 min read
Foundation CSS Tabs
Foundation CSS is an open-source & responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing & can be accessible to any device. It is used by many companies such as Facebook, eBay,
3 min read
Foundation CSS JavaScript Programmatic Use
Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. This framework
4 min read
Foundation CSS JavaScript Throttle Utility
Foundation CSS is an open-source front-end framework that is used to create a beautiful responsive website, apps, or email quickly and easily. ZURB published it in September of that year. Numerous businesses, like Facebook, eBay, Mozilla, Adobe, and even Disney, make use of it. This framework, which
2 min read
JavaScript Function Examples
A function in JavaScript is a set of statements that perform a specific task. It takes inputs, and performs computation, and produces output. The idea is to put some commonly or repeatedly done tasks together and make a function so that instead of writing the same code again and again for different
3 min read