The combination of Inline CSS and Bootstrap classes does not seem to be functioning properly

I'm new to web design and currently working on a website project. My concept involves hiding the #login-box when the user clicks on the login button, and displaying another element (.dashboard) in its place. Initially, I set the .dashboard class to have display: none so it would be hidden by default. Then, I wrote some JavaScript code to hide the #login-box and show the .dashboard element upon clicking the login button.

My Code:

const loginBoxEl = document.getElementById("login-box");
const loginBtnEl = document.getElementById("login-btn");
const dashboardEl = document.getElementById("dashboard");

loginBtnEl.addEventListener("click", function() {
    loginBoxEl.style.display = "none";
    dashboardEl.style.display = "block";
});
#login-box {
    height: 100vh;
}

#login-area {
    border-radius: 8px;
    box-shadow: 5px 5px 10px lightgray;
}

#dashboard {
    display: none;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8>
    <title>Unique Webpage Title</title>
    <link rel="stylesheet" href="./styles.css>
</head>
<body>
    <div id="login-box>
        <div id="login-area">
            <h1>Welcome to Our Website</h1>
            <input type="email" placeholder="Email" required>
            <input type="password" placeholder="Password" required>
            <button id="login-btn">Login</button>
        </div>
    </div>

    <div id="dashboard">
        <h1>Dashboard</h1>
    </div>

    <script src="./main.js"></script>
</body>
</html>

Although the .dashboard is correctly displayed upon clicking the login button, the #login-box does not disappear despite the inline CSS setting display: none. How can I address this issue?

Answer №1

const loginBoxEl = document.getElementById("login-box");
    const loginBtnEl = document.getElementById("login-btn");
    const dashboardEl = document.getElementById("dashboard");

    loginBtnEl.addEventListener("click", function() {
    loginBoxEl.classList.add("hide_login");;
    dashboardEl.style.display = "block";
    });
#login-box {
    height: 100vh;
}

#login-area {
    border-radius: 8px;
    box-shadow: 5px 5px 10px lightgray;
}

#dashboard {
    display: none;
}
.hide_login{
  display: none!important;
}
<div class="d-flex justify-content-center align-items-center" id="login-box">
  <div class="p-5" id="login-area">
      <h1 class="bank-title">Welcome to Payoneer</h1>
      <input class="form-control my-3" type="email" placeholder="E-mail" required>
      <input class="form-control my-3" type="password" placeholder="Password" required>
      <button class="btn btn-success" type="submit" id="login-btn">Log in</button>
  </div>
</div>

<!-- Dashboard -->
<div id="dashboard">
  <h1>Dashboard</h1>
</div>

Answer №2

I have implemented jQuery and modified the click event as required. Please review it.

$(document).ready(function() {
    // This code will execute because we are listening for a click on the 'document' 
    // with the ID of #test-element
    $(document).on("click","#login-btn",function() {
        $('#login-box').removeClass('d-flex');
        $('#login-box').css('display','none');
        $('#dashboard').css('display','block');
    });
    
});
#login-box {
    height: 100vh;
}

#login-area {
    border-radius: 8px;
    box-shadow: 5px 5px 10px lightgray;
}

#dashboard {
    display: none;
}
<!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">
    <title>Payoneer Bank Account | John Doe</title>
    <!-- Bootstrap CSS CDN -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <!-- Custom CSS -->
</head>
<body>
    <!-- Login Box -->
    <div class="d-flex justify-content-center align-items-center" id="login-box">
        <div class="p-5" id="login-area">
            <h1 class="bank-title">Welcome to Payoneer</h1>
            <input class="form-control my-3" type="email" placeholder="E-mail" required>
            <input class="form-control my-3" type="password" placeholder="Password" required>
            <button class="btn btn-success" type="submit" id="login-btn">Log in</button>
        </div>
    </div>

    <!-- Dashboard -->
    <div id="dashboard">
        <h1>Dashboard</h1>
    </div>

    <!-- Bootstrap JavaScript CDN -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>

</body>
</html>

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

Modify the values of several dropdown menus (5 in total) at once using jQuery. The values will be dynamically retrieved from a JSON file

Dropdown values for the first dropdown are 1, 2, 3, 4, 5. Dropdown values for the second dropdown are 25, 26, 27, 28, 29. Dropdown values for the third dropdown are 35, 36, 37, 38, 39. The goal is to have each dropdown loaded with its respective data dyn ...

CSS is functioning properly on a local level, but fails to take effect once the "npm run build" command is executed in the React application's build

I am attempting to override the CSS of Muidrawer-paper. It works locally after running "npm start", but it does not take effect when building the package. .css-12i7wg6-MuiPaper-root-MuiDrawer-paper { position: absolute !important; top: 50px !import ...

Ways to view the outcome of json_encode function?

In PHP, I have an array that looks like this: $user_data = Array ( [session_id] => 30a6cf574ebbdb11154ff134f6ccf4ea [ip_address] => 127.0.0.1 [user_agent] => Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1 [las ...

What is the best method for installing a package specified as a peerDependency?

I'm in the process of creating a library and I'm looking to figure out how to specify and install a dependency under peerDependencies. I couldn't find any information about this in the npm documentation when using the command npm install: ...

Tips for implementing a toggle feature for an ion-card element

I am looking to create a toggle effect on ion-card, where clicking on the card will highlight it until either unclicked or another card is clicked. Similar to this - https://i.sstatic.net/MH5WA.png How can I achieve this effect on ion-card? Here is my H ...

Stopping the papaparse streaming process once a certain number of results have been achieved

Currently, I am utilizing the PapaParse library to parse a large CSV file in chunk mode. During my data validation process, I encountered an issue where I was unable to stop streaming the data once validation failed. I attempted to halt the streaming by ...

Using Jquery to toggle a class on click, and dynamically change based on the screen size

I am trying to figure out how to toggle a CSS class on an element by clicking on a div using jQuery. I know how to do it, but I also want the toggle to only happen when the screen size is less than 800px. I'm not very familiar with JavaScript, so I co ...

Utilizing data as a substitute when creating a SearchBar using Vue3

My VueJs3 application has a search bar implemented using .filter(), and it seems to be working fine. However, when I try to pass the value from my methods to the template, an error occurs. My data becomes a proxy and I am unable to use it in that format. ...

Prepending a string to the key of a JSON object using JavaScript

Is there a way to add 'd:' before the key of a JSON object? Here is the JSON data: "data": { "aa": "value", "ab": "value" } The expected result should look like this: "d:data": ...

What is the reason that `font-size` does not match the `height`? For example, if the `<span>` on the left is 2rem, on the right I could fit 2 smaller `<span>`s, each with a size of 1rem

How can I achieve a layout like this? Essentially, I have 2 containers in flexbox: The first one with text "33" The second one is a grid container: The first element in the grid is "EUR" The second element in the grid is ".49" Based on this descript ...

Is there a way to modify HTML using a C# program in a web browser?

I’m considering the possibility of editing the HTML document text through the web browser. I am currently working on an email client that utilizes an HTML template for its design. Everything seems to be in order, but now I need to customize the template ...

JavaScript code using jQuery's ajax method is sending a request to a PHP server, but

Attempting to utilize jQuery ajax for PHP call and JSON return. The test is quite simple, but only receiving an empty object in response. No PHP errors appearing in the LOG File. jqXHR is recognized as an object with 'alert', yet not displayin ...

Align two divs to the left and the other one to the right

Here is the current structure of my code: <div style="height: 100px; Width: 200px;"> <!-- Container --> <div style="float: left; height: 50px; Width: 100px; background-color: ...

Date range within a conditional statement

I have encountered this code snippet: function auto_select_param_call_time() { if (today() == date("02.01.2017") || today() == date("03.01.2017")) { auto_click_param("call_time", "Non-working day"); } else { //Do something else ...

What is the process for clearing the cache of a crawling URL?

Currently, I am operating a crawler that gets triggered through an expressjs call. However, whenever I make the same request again, the crawler runs once more but indicates that all routes have already been completed. I even went to the extent of deleting ...

What is the ternary operation syntax for setting the img src attribute in Angular 8?

My data includes a property called "photo" which can either have a file name or be empty. For instance, it could be "steve.jpg" or just an empty string if Steve does not have a photo. In React JSX, I know how to use a ternary operator with the "photo" va ...

Is it possible to evaluate the complexity of automating the user interface of a web application?

What are some common indicators of the challenges involved in automating the frontend of a web application? One example could be ensuring that all “critical” elements have stable ID attributes that do not change frequently. Are there any other similar ...

What purpose do controller.$viewValue and controller.$modelValue serve in the Angular framework?

I'm confused about the connection between scope.ngModel and controller.$viewValue/controller.$modelValue/controller.$setViewValue(). I'm specifically unsure of the purpose of the latter three. Take a look at this jsfiddle: <input type="text" ...

issues with functionality in purecss drop down menu

I have been struggling to create a vertical drop-down menu using the purecss library without success. purecss.io/menus/ This is what my CSS code looks like: <div class="pure-menu custom-restricted-width"> <ul class="pure-menu-list"> ...

Is there a way to modify the button's color upon clicking in a React application?

I am a beginner in the world of React and currently exploring how to utilize the useState hook to dynamically change the color of a button upon clicking. Can someone kindly guide me through the process? Below is my current code snippet: import { Button } ...