Foundation CSS JavaScript Events
Last Updated :
05 Feb, 2023
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.
Foundation CSS JavaScript events are triggered when certain actions are performed on the website, such as clicking a button or hovering over an element. You can use event listeners to listen to these events and execute code when they occur.
JavaScript events are actions that can occur in a web page, such as a user clicking a button or hovering over an element. You can use event listeners in JavaScript to execute code when these events occur.
Syntax:
$("id_selector").eventname(function(){
// Code here
})
Here, id_selector is the id of the component, and the Javascript event is used in place of eventname.
Example 1: The following code display an alert message when a user clicks a button using Foundation CSS and JavaScript event.
- In this code, the jQuery library is included to handle the click event, the JavaScript file is included for additional functionality, and the Foundation CSS method is called to initialize the framework.
- When the button is clicked, the click event listener is triggered, and the alert message is displayed.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Button Alert</title>
<!-- Include the Foundation CSS file -->
<link rel="stylesheet" href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/foundation.min.css"
integrity=
"sha256-ogmFxjqiTMnZhxCqVmcqTvjfe1Y/ec4WaRj/aQPvn+I="
crossorigin="anonymous">
<!-- Include the jQuery library -->
<script src=
"https://code.jquery.com/jquery-3.6.0.min.js">
</script>
<!-- Include the Foundation JavaScript file -->
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/foundation.min.js"
integrity=
"sha256-pRF3zifJRA9jXGv++b06qwtSqX1byFQOLjqa2PTEb2o="
crossorigin="anonymous">
</script>
</head>
<body>
<center>
<h1 style=color:green>GeeksforGeeks</h1>
<h3>Foundation CSS JavaScript Events</h3>
<!-- Create a button element -->
<button id="alert-button" style="color:blue">
Click me
</button>
</center>
<!-- Initialize Foundation -->
<script>
$(document).foundation();
</script>
<!-- Add a click event listener to the button -->
<script>
$(document).ready(function() {
$("#alert-button").click(function() {
// Display an alert message when
// the button is clicked
alert("You clicked the button!");
});
});
</script>
</body>
</html>
Output:
Example 2: The following code display an alert message when a user mouseovers a button using Foundation CSS and JavaScript event.
- This code includes the jQuery library to handle the mouseover event and the Foundation JavaScript file for additional functionality.
- When the button is mousehovered, the mouseover event listener is triggered, and the alert message is displayed.
HTML
<!DOCTYPE html>
<html>
<head>
<title>mouseover Alert</title>
<!-- Include the Foundation CSS file -->
<link rel="stylesheet" href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/foundation.min.css"
integrity=
"sha256-ogmFxjqiTMnZhxCqVmcqTvjfe1Y/ec4WaRj/aQPvn+I="
crossorigin="anonymous">
<!-- Include the jQuery library -->
<script src=
"https://code.jquery.com/jquery-3.6.0.min.js">
</script>
<!-- Include the Foundation JavaScript file -->
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/foundation.min.js"
integrity=
"sha256-pRF3zifJRA9jXGv++b06qwtSqX1byFQOLjqa2PTEb2o="
crossorigin="anonymous">
</script>
</head>
<body>
<center>
<h1 style="color:green">GeeksforGeeks</h1>
<h3>Foundatation Css Javascript Alerts</h3>
<!-- Create a button element -->
<button id="alert-button">Hover me</button>
</center>
<!-- Initialize Foundation -->
<script>
$(document).foundation();
</script>
<!-- Add a mouseover event listener to the button -->
<script>
$(document).ready(function() {
$("#alert-button").mouseover(function() {
// Display an alert message when the button
// is mouseovered
alert("You hovered over the button!");
});
});
</script>
</body>
</html>
Output:
Similar Reads
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 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
JavaScript Custom Events Custom events are events created by developers to perform specific actions. They allow different parts of an application to communicate without being tightly connected. These events can be linked to elements or objects, and when triggered, they run certain tasks. How to Create and Trigger Custom Eve
4 min read
JavaScript Custom Events Custom events are events created by developers to perform specific actions. They allow different parts of an application to communicate without being tightly connected. These events can be linked to elements or objects, and when triggered, they run certain tasks. How to Create and Trigger Custom Eve
4 min read
JavaScript Custom Events Custom events are events created by developers to perform specific actions. They allow different parts of an application to communicate without being tightly connected. These events can be linked to elements or objects, and when triggered, they run certain tasks. How to Create and Trigger Custom Eve
4 min read
JavaScript Events JavaScript Events are actions or occurrences that happen in the browser. They can be triggered by various user interactions or by the browser itself. HTML<html> <script> function myFun() { document.getElementById( "gfg").innerHTML = "GeeksforGeeks"; } </script> <body> <but
3 min read