Issues with activating jquery toggle function

Could someone help me figure out why this code isn't functioning as expected?

HTML

<head>
<body id="top" class="home page page-id-1412 page-template-default logged-in stretched open_sans open_sans siteorigin-panels" itemtype="http://schema.org/WebPage" itemscope="itemscope">
        <div id="wrap_all">
            <header id="header" class="header_color light_bg_color mobile_drop_down" itemtype="http://schema.org/WPHeader" itemscope="itemscope" role="banner">
                <div id="header_meta" class="container_wrap container_wrap_meta">
                <div id="header_main" class="container_wrap container_wrap_logo">
                <div id="header_main_alternate" class="container_wrap">
                    <div class="container">
                        <nav class="main_menu" itemtype="http://schema.org/SiteNavigationElement" itemscope="itemscope" role="navigation" data-selectname="Select a page">
                           <div id="megaMenu-sticky-wrapper">
                             <div id="megaMenu" class="megaMenuContainer megaMenuHorizontal wpmega-preset-vanilla megaResponsive megaResponsiveToggle wpmega-withjs megaMenuOnClick megaFullWidth wpmega-noconflict megaMinimizeResiduals themeloc-avia megaMenu-withjs">
                                <div id="megaMenuToggle" class="megaMenuToggle">
                                <ul id="megaUber" class="megaMenu">
                                    <li id="menu-item-8" class="jrm-um-sticky-only menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home ss-nav-menu-item-0 ss-nav-menu-item-depth-0 ss-nav-menu-reg um-flyout-align-center ss-nav-menu-with-img ss-nav-menu-notext">
                                    <li id="menu-item-1459" class="my_custom_class menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children mega-with-sub ss-nav-menu-item-1 ss-nav-menu-item-depth-0 ss-nav-menu-mega ss-nav-menu-mega-fullWidth mega-colgroup mega-colgroup-6 ss-nav-menu-mega-alignCenter">
                                        <a href="#">

CSS

#overlay-2 {
height: 100%;
width: 100%;
position: fixed;
left: 0;
top: 0;
background: none repeat scroll 0 0 #000000;
opacity: 0.85;  
z-index: 10;
display: none;
}

JS

$(document).ready(function() {

    $('.my_custom_class').click(function()    {
       $('#overlay-2').toggle();
    });
});

I'm aiming for the #overlay-2 to be hidden on page load and then toggle show/hide when using the menu button with the custom class assigned in WordPress nav menu "css classes" metabox. The class I applied is .my_custom_class.

What could possibly be causing this not to work? If you're able to provide corrected code, that would be greatly appreciated :)

Thank you!

Answer №1

Since there is no .my_custom_class in your HTML, that's why it's not working.

To fix this issue, include the following code snippet:

<button class="my_custom_class">Toggle Overlay</button>

Make sure to add it both in your main document and inside the overlay for it to work properly:

VIEW LIVE DEMO

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to keep my navbar fixed at the top as I scroll down the page? And is it possible to have a picture appear above the navbar when scrolling up to the top?

I am looking to create a design where a picture appears above my navbar, and as I scroll down, I want the picture to stay fixed at the top so that it is always visible, regardless of how much I scroll. However, when scrolling back up, I want the picture to ...

Adjust the size of grid items when the user scrolls in a React

I am trying to implement an animation on my grid items where they shrink and expand as the user scrolls, similar to the effect seen on this website . So far, I have made no progress on this. Can anyone provide me with a hint, suggest a package that can hel ...

Manipulating variables across various methods in TypeScript

I have a simple code snippet where two variables are defined in the Main method and I need to access them from another method. However, I am encountering an issue with 'variables are not defined', even though I specified them in the declerations ...

Add a script tag to every image in my HTML at once using C#

Managing a site with a thousand images can be overwhelming, especially when trying to add a script tag like <%=Settings.MyDomain%> to each one. I'm looking for a more efficient way to accomplish this task without spending hours on manual labor. ...

Unexpected disconnection from Socket.io server

Utilizing node.js service and angular client with socket.io for extended duration http requests. Service: export const socketArray: SocketIO.Socket[] = []; export let socketMapping: {[socketId: string]: number} = {}; const socketRegister: hapi.Plugin< ...

Assign an onClick event to a Button that was dynamically generated within a loop in JavaScript

Is there a way to set the onClick property for buttons created within a loop? I've tried using JQuery with no success. for(started somewhere... var button = document.createElement('button') var div = document.createEl ...

Interacting with dropdown menus on webpages through select box events

I am looking to create a unique scrollable drop-down menu on a webpage that includes select box features like hover on key press. For instance: Within my drop-down menu, there are approximately 100 elements, Apple Ant Ball Orange .... The menu should be ...

What is the best way to establish a header in the login route that allows the browser to remember the user's login status?

I have successfully implemented a user login backend and everything seems to be working fine. However, when I try to access a user detail after logging in, I am faced with an authorization issue preventing me from exploring other routes. How can I store th ...

The ng-repeat directive in my Angular app's div element is being displayed as a comment

After spending several days searching, I have yet to find a solution for my issue. It seems to be specific to the code I'm working with in Angular 1.6. I apologize for the format of my post, as this is my first time seeking help on stack overflow ...

Is it possible to use a jQuery plugin on a hidden div?

Dealing with some jquery tabs here. I've incorporated a plugin for a scrolling pane of options within the tabs, but it seems to malfunction when clicking on a tab that was hidden on initial page load. Even tried initiating the plugin using the :hidden ...

Tips for managing data from two distinct web pages within a single controller in angular.js

I am currently working on developing a web page using Angular.js that allows users to create tasks on the server. Each task requires APIs, but I don't want to enter APIs every time I create a new task. I am looking for a way to input APIs only once wi ...

Changing the width of a label in jQuery Mobile

In an effort to enhance the appearance of all label tags within a jquery mobile form, we are aiming to adjust their widths based on the largest label. Below is a code snippet illustrating this for one specific field: ... <fieldset data-role="fieldconta ...

React: The error message "p is not defined" is showing up in the component file due to the no-undef

In my React application, I am looking to display a list of menu items from an array and show the detailed description of each item upon clicking. The array of menu items is stored in a separate file called dishes.js. The menu items are rendered using a Me ...

Unlock AngularJS expression through ng-click functionality

I've encountered an issue with accessing AngularJS expressions after a click event takes place. index.html <div class="row"> <a href="#/company"><div class="tile col col-comp cat-a-g grow-appear" ng-click="onSelect(item)" ng-repea ...

Looking for assistance with extracting only numerical values from a webpage using Selenium in Python

Website Elements <td style="font-size:20px;font-family:LucidaGrande,tahoma,verdana,arial,sans-serif;padding:10px;background-color:#f2f2f2;border-left:1px solid #ccc;border-right:1px solid #ccc;border-top:1px solid #ccc;border-bottom:1px solid #ccc; ...

Google Maps/Advanced Custom Fields/JointsWP is experiencing an issue with the absence of jQuery

Utilizing WordPress along with Advanced Custom Fields and the JointsWP (Foundation 5) theme to create a map displaying multiple pins from a custom post type using the Google Map field from Advanced Custom Fields. Previously achieved this on Bootstrap3 with ...

Unlocking targeted web elements with Selenium and Python

I am encountering an issue while trying to interact with an element on a website. Despite my script running, it seems unable to locate the specific element. When I use Python Shell and input: z = browser.find_element_by_css_selector("input[name='0_40 ...

Update all other input fields whenever a single field is modified. Implement using AngularJS (Link to Plunker included)

Check out this plunker example at http://plnkr.co/edit/Ll09uMtJEC0HqyGBRPj?p=preview Within the plunker, there are input fields for date, user, and car. It is possible to select values for all three fields. If I attempt to change the date, I would like ...

How can we validate a form using Bootstrap Validator and Image Picker when either of the two select inputs is selected?

Currently, I am utilizing the bootstrap-validator plugin for form validation and the imagePicker plugin to display selects in my project. While these plugins work well together, I have encountered a situation that I am unable to resolve independently. Spec ...

Ajax transmitting data with concealed characters

I'm trying to send data from one PHP site to another. On the first site, everything looks good. The string appears as --show="author,book,text/n However, when I check the string after receiving it on the second site, it shows --show="author,b ...