Is there a way for me to conceal my table upon clicking on the sidebar? Additionally, when I click on a button to display a different table, can the currently visible table automatically close?

I have a unique table for each button. Initially, the tables are hidden using CSS visibility: 'hidden', and when I click a button, the corresponding table displays. However, the issue arises when I click the same button again as it fails to hide the table. Additionally, clicking on other buttons should hide the currently displayed table and show another one.

 function toggle() {
          if( document.getElementById("Patient-Table").style.visibility='hidden' )
            {
              document.getElementById("Patient-Table").style.visibility = 'visible';
            }
          
          else{
              document.getElementById("Patient-Table").remove(visibility);
          }
        }
#Patient-Table {
    visibility: hidden;
}
<div id="Patient-Table" class="container col-sm-8">
      <div class="table-wrapper">
        <div class="table-title">
          <div class="row">
              <div class="col-sm-6">
                 <h2>List of <b> Patients</b></h2>
              </div>
              <div class="col-sm-6">
                <form class="d-flex" role="search">
                  <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
                  <button class="btn btn-outline-success" type="submit">Search</button>
                </form>
             </div>
        <div class="tables border shadow border-3 mt-3 mb-5">
        <table class="table">
            <thead>
          <tr>
            <th>ID</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Gender</th>
            <th>Age</th>
            <th>Email</th>
            <th>Phone</th>
            <th>Address</th>
            <th>Action</th>
          </tr>
        </thead>
            <tbody>
                <tr>
                        <td>1</td>
                        <td>Low</td>
                        <td>Key</td>
                        <td>Male</td>
                        <td>27</td>
                        <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d8dbc39adfd1cdf4d3d9d5ddd89ad7dbd9">[email protected]</a></td>
                        <td>+673668292</td>
                        <td>NewyorkUSA</td>
                        <td>
                            <a class='btn btn-primary btn-sm' href='update'>Update</a>
                            <a class='btn btn-danger btn-sm' href='delete'>Delete</a>
                        </td>
                    </tr>
                    <tr>
                      <td>2</td>
                      <td>Low</td>
                      <td>Key</td>
                      <td>Male</td>
                      <td>27</td>
                      <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="deb2b1a9f0b5bba79eb9b3bfb7b2f0bdb1b3">[email protected]</a></td>
                      <td>+673668292</td>
                      <td>NewyorkUSA</td>
                      <td>
                          <a class='btn btn-primary btn-sm' href='update'>Update</a>
                          <a class='btn btn-danger btn-sm' href='delete'>Delete</a>
                      </td>
                  </tr>  
                  <tr>
                    <td>3 </td>
                    <td>Low</td>
                    <td>Key</td>
                    <td>Male</td>
                    <td>27</td>
                    <td><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="670b0810490c021e27000a060e0b4904080a">[email protected]</a></td>
                    <td>+673668292</td>
                    <td>NewyorkUSA</td>
                    <td>
                        <a class='btn btn-primary btn-sm' href='update'>Update</a>
                        <a class='btn btn-danger btn-sm' href='delete'>Delete</a>
                    </td>
                </tr>    
            </tbody>
        </table>

Answer №1

 function togglePatientVisibility() {
          let table = document.getElementById("Patient-Table");
           if(table.style.display == "none") {
              table.style.display = "block";
           }else{
           table.style.display = "none";
           }
        }

Here is my revised JavaScript code

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

Issue: The function connect.compress is not defined

I am currently working on a project that is primarily written in TypeScript and then transpiled into JavaScript. The backend is built with Node, while the frontend uses React Native. Recently, after updating to Babel6, we started encountering numerous erro ...

jQuery has successfully delivered the message of success

I have both success and error images available. I want to display a success message using jQuery. Specifically, I would like to show this message in a label control using a CSS class that I created called "success". Can anyone help me with this? When I us ...

Exploring alternative methods of iterating over the values in a key-value pair within an AngularJS framework

My key-value pair consists of a long list of file names stored in the variable $ctrl.displayData- 143:"/this/is/a/very/long/fil22↵/this/is/a/very/long/file/path.php↵anotherone.php↵newfilel123.php" When I use ng-repeat to display these file names, t ...

What is the best way to halt a specific function in jQuery?

I recently developed a website for my photographer friend, and I implemented a feature where the home page is initially blurred. Visitors can click a button to unblur the content. While the functionality works smoothly, there's one issue - every time ...

Setting up the Bootstrap grid structure

Struggling to find the right configuration for this Bootstrap 3 setup... https://i.stack.imgur.com/ZsTdI.png I have an input field, but I'm having trouble placing the image in that position. <div class="row"> <div class="col-sm-4 col-m ...

Highlighting an Element Using Selenium Webdriver at Specific Coordinates

I'm currently in the process of automating a web application built with HTML5 using Selenium Webdriver. I need help figuring out how to highlight the exact coordinates where I have clicked on the Canvas element. For example, if I click on the Canvas a ...

The modal dialog feature in HTML5 and CSS3 seems to be experiencing some issues when used in Opera browser

This informative post provides a detailed tutorial on creating a modal dialog using only HTML and CSS3. For more information, visit: To see a working demo, click here: The modal works flawlessly in most browsers, but some users have reported issues with ...

Having trouble with a jQuery slideshow when populating a div from a JSON feed?

$(document).ready(function() { $.getJSON("http://api.flickr.com/services/feeds/groups_pool.gne?id=89254480@N00&\ lang=en-us&format=json&jsoncallback=?", getJSONimages); function getJSONimages(data) { var htmlString = ""; $.each(data.item ...

The Mootools element with the Object #<HTMLDivElement> does not support the addEvent method

$$('.img-default > a')[0] Retrieves the correct element from the DOM, but I am unable to attach an event. This bit of code: $$('.img-default > a')[0].addEvent('click', function(){ //GA code }); produces the followin ...

Webpage not resizing when WebView orientation changes

While developing my android app, I encountered an issue with the WebView. When I am at the very top of the WebView and switch my phone to landscape mode, the webpage does not resize properly to fit the screen. It only takes up half of the screen. However, ...

Linked selection options for state, city, and postal code

I have set up a cascading dropdown list - State -> City -> Pincode . Instead of fetching data from the database, I am using JSON. The dropdown functions smoothly on the local server, but experiences slowness on the web server. Here is a snippet of ...

Error message: Unable to access the state property of an undefined object

I've been attempting to integrate a react sticky header into my stepper component. However, I've encountered an issue where it doesn't render when added inside my App.js file. As a result, I've started debugging the code within App.js ...

Calculating the total of all values in a table

For my ngFor loop, the invoice total is calculated based on price and hours, but I also want to calculate the totals of all invoices in the end. <tr *ngFor="let invoice of invoiceItem.rows"> <td>{{ invoice.rowName }}</td> <td& ...

What is causing the issue with dynamic special characters not functioning properly in my React router?

I am working with 3 components named App.js, SearchCategoryPage.js, and Home.js. However, when I click on the search icon, it does not navigate me to the search page. What could be the reason for this issue? App.js const outlet_id = useSelector((state) =& ...

Dealing with an endless loop caused by a promise in AngularJS's ui router $stateChangeStart event

I am currently working on implementing authentication in my Angular application and I want to redirect to an external URL when a user is not logged in (based on a $http.get request). However, I seem to be stuck in an infinite loop when using event.prevent ...

Error in compiled.php on line 7772: Laravel throwing a RuntimeException when sending HTTP requests from Angular

Hey there, I've been encountering an error intermittently while using Angular $http methods with a Laravel API. Can someone please explain what this error means and suggest potential solutions? I've shared the error log on CodePen for easier refe ...

The requested page for angular-in-memory-web-api could not be located within the Angular 4.2.2 CLI web-api functionality

Currently, I am delving into the Angular framework (specifically version 4.2.2) and going through the Tour of Heroes tutorial. As I progressed to the HTTP section, the tutorial introduced the use of angular-in-memory-web-api to simulate a web api server. ...

Display HTML in JavaScript without altering the Document Object Model

Is it possible to style a custom HTML tag called "location" without directly modifying the DOM? For instance, having <location loc-id="14" address="blah" zipcode="14" /> Would it be feasible to render it like this: <div class="location"> ...

How can Vue 3's v-bind=$attrs be implemented effectively?

I am currently in the process of migrating my Vue 2 application to Vue 3. According to the official documentation, the $listeners object has been removed in Vue 3 and event listeners are now part of $attrs. This includes taking non-prop attributes like cla ...

Create groupings within an array based on the month and year using JavaScript

I am working with an array that looks like this: var v = ["07/27/2015", "07/28/2015", "08/29/2015", "08/29/2015", "07/27/2016"] My goal is to dynamically sort this array into a new empty array nv. Once sorted, nv should look like this: var nv = [["07/27 ...