Open In App

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.

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.




<!DOCTYPE html>
<html>
<head>
    <title>Button Alert</title>
    <!-- Include the Foundation CSS file -->
    <link rel="stylesheet" href=
        integrity=
"sha256-ogmFxjqiTMnZhxCqVmcqTvjfe1Y/ec4WaRj/aQPvn+I=" 
        crossorigin="anonymous">
    <!-- Include the jQuery library -->
    <script src=
    </script>
      <!-- Include the Foundation JavaScript file -->
    <script src=
            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.




<!DOCTYPE html>
<html>
<head>
    <title>mouseover Alert</title>
    <!-- Include the Foundation CSS file -->
    <link rel="stylesheet" href=
        integrity=
"sha256-ogmFxjqiTMnZhxCqVmcqTvjfe1Y/ec4WaRj/aQPvn+I=" 
        crossorigin="anonymous">
    <!-- Include the jQuery library -->
    <script src=
    </script>
      <!-- Include the Foundation JavaScript file -->
    <script src=
            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:

 


Article Tags :