The button is not triggering the jQuery modal to appear when clicked

Trying to make a modal window appear after clicking the sign-in button in the navigation bar, but running into some issues. Both the modal and its overlay are initially set to 'display: none' in CSS. Have attempted various methods like fadeIn(), .css(), and creating a special class with only 'display: none' and using .removeClass(), but nothing seems to be working as expected.

This is for a school project, so jQuery UI is not an option. Just looking for guidance on how to proceed. Here's the current code:

$(document).ready(function() {
    $('#login').click(function(event) {
        event.preventDefault();
        $('.overlay').removeClass('.displaynone');
        $('.modal').removeClass('.displaynone');
    });
});

Find the complete scenario in this JS Fiddle link. The goal is for clicking the Log In button to display the overlay and modal window, ideally with a fade-in effect and a delay on the modal:

Fiddle: https://jsfiddle.net/duagdn8m/1/

Answer №1

You should avoid using . in the class names. It is unnecessary as shown here:

$('.overlay').removeClass('displaynone');
$('.modal').removeClass('displaynone');

Fiddle: https://jsfiddle.net/cnye843k/

Consider implementing an absolute positioning for the login screen to create a modal effect. If you haven't included the CSS, that's okay too.

Answer №2

Check out this solution on JSFiddle All you need to do is eliminate the period in front of the class name that you wish to remove.

$('.overlay').removeClass('displaynone');
$('.modal').removeClass('displaynone');

Answer №3

To fix the issue, remove the . in removeClass('.displaynone');. Additionally, remember that overlay and modal are classes, not ids, so update your CSS to use .overlay and .modal.

For an easier approach, initially set both overlay and modal to display:none; and then fade them in simultaneously:

$(document).ready(function() {
    $('#login').click(function(event) {
        event.preventDefault();
        $('.overlay, .modal').fadeIn(1000)
    });
});

This will provide a smooth 1-second fade-in effect.

Fiddle

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

.js script not being rendered within the ng-view

I am facing an issue with my index.html file which contains ng-view. I have included the necessary .js files in the index.html, but these scripts are not being applied to the injected view. index.html <!DOCTYPE html> <html class="no-js css-menub ...

The functionality of AJAX is currently disabled in macOS WebView

I have developed a WebView for a macOS application that includes an AJAX call. Interestingly, the WebView functions perfectly when it accesses my local URL. However, it encounters issues with the AJAX call when attempting to access the live URL. $(documen ...

Tips for modifying the color of the input field in Ionic 5 upon receiving focus

Is there a way to change the color of an input field when it's focused? Currently, it turns grey only when focused by a function and remains so until typing or clicking on the field. export function autofocus() { let blanks = document.querySelecto ...

Initiating a YouTube video with a click on its thumbnail image - a jQuery tutorial

I am currently working on code that successfully displays YouTube videos. However, I would like the video to start playing when the cover image is clicked. How can I achieve this functionality? Thank you for your help! <div id="video" style="display: ...

Turn off the href function, perform some ajax operations, then turn the href function back on

here is the issue at hand : I am facing a problem where I have a tag, and when it is clicked, the href value triggers a popup (fancybox), <a class="myIdentifier" href="#myPopup">pop</a> However, upon clicking on it, I need to perform some ...

Employ Ajax for updating a database using a Select option instead of a form with a button

My goal is to utilize ajax in order to select an option and store the data in a database, rather than using a select within a form along with a button. This approach is necessary because I have one select for each row, and every time I change the selected ...

Blank canvas for exploring SQL and PHP queries

I am currently working on a website that displays personal statistics for users. To achieve this, I am utilizing PHP to retrieve data from an SQL database. Below are the two files I am using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...

The failure of the data-target selector in Bootstrap collapse feature

I've been attempting to collapse multiple targets with just one click. The Bootstrap documentation suggests that this can be achieved by specifying a matching CSS selector with the data-target attribute. However, it seems that the collapsing only work ...

Is it possible for web browsers to accommodate various HTML5 pattern regexp functionalities?

A basic regular expression pattern was implemented in a payment form on our website for customers: <input type="text" pattern="(|\$)[0-9]*(|\.[0-9]{2})" title="Please enter a valid number in the amount field" required> This pattern ...

Transmitting information compiled into an array format using AJAX and JQuery

I'm seeking assistance with sending my data efficiently. Previously, the script I developed served as a Mass Acknowledgments Tool for Nagios, drawing inspiration from components available for NagiosXI. Initially, the data processing and sending were ...

Problems arise with MySQL queries on specific hosting plans

For some time, I have been developing a website on a subdomain within my employer's hosting package. This site involves PHP MySQL operations like INSERTs and SELECTs. All the basic SQL statements are functioning correctly without any issues. However ...

Extract information from page 1 to page 2 by utilizing ajax

Greetings, I am currently facing an issue with parsing data using the href get method to retrieve PHP by ajax on another page. Is this achievable? By the way, my framework of choice is CODEIGNITER. This is my HTML href code snippet: <a href="'.b ...

There are issues with React Grid2 not adhering to specified row and column definitions and lacking

I am currently in the process of creating a website with react, and I have reached the point where I need to showcase some products. To achieve this, I am utilizing React's Grid2 due to its flexibility for customization and responsiveness to different ...

Is it possible for jquery to run an entire HTML file using ajax?

Based on information from a discussion on Stack Overflow, it seems that I can utilize the jquery getScript() method to run a remote JavaScript file loaded via Ajax. However, in my specific scenario, the script file is located within an HTML file. Is ther ...

What methods can I use to interpret this incorrect JSON data in jQuery?

Is it possible to access the different pieces of data within this specific data attribute? <div class="location" data="{id: 4, point: {lng: -71.413364, lat: 41.673681}, category: 'Restaurant'}"> While it's quite simple to retrieve th ...

When there is only a single div content in Ant Design Vue, Carousel arrows have been observed to disappear

I have integrated the Ant Design Vue Carousel into my Instagram Story Clone project to showcase dynamically generated backend data. However, I've encountered an issue where the arrows and dots disappear when there is only one item in the carousel. Y ...

JSON syntax error: "r" is not a valid token at the beginning position

Currently, I am in the process of developing a web server that is based on STM32 MCU. The workflow involves the browser sending a request to the MCU, which responds with a web HTML file. Users can then adjust parameters and use a form to submit them back t ...

How can you reference the immediate selector object using jQuery?

I'm currently delving into the realm of jQuery and decided to create a test page equipped with the following code: <a id='encode' href='javascript: void(0)'>encode</a> | <a id='decode' href='javascr ...

Guide for displaying UTF-8 characters in template tool kit by passing dropdown options

Currently, I am working on adding UTF-8 character support to my project which utilizes the template tool kit. Within one of the templates, there is a hard-coded dropdown code that is causing issues with text translation. Here is the snippet of the code: ...

Is it considered acceptable to employ an endless loop to continually monitor the connection to a server?

Today marks the beginning of my journey in creating an Angular App. My goal is to establish a connection to a server and display a message on screen if the connection is offline, prompting the user to check their network settings. I currently have a JavaSc ...