Switching the active and inactive states of a class with EventListeners

I'm currently working on a login page for a website and I've added a toggle button as a label for a checkbox. However, I'm struggling to toggle the active/inactive state of the class using JavaScript click EventListeners. Any suggestions or guidance would be greatly appreciated.

let switcher = document.getElementsByClassName('switch')[0];
switcher.addEventListener('click', () => {
    switcher.toggle = 'active';
})
input[type="checkbox"] {
    width: 0px;
    height: 0px;
    opacity: 0;
}

.switch {
    display: inline-block;
    padding: 4px;
    height: 22px;
    width: 60px;
    background-color: rgb(110,116,143);
    border-radius: 20px;
}

.slider{
    display: inline-block;
    border-radius: 20px;
    background-color: rgb(255,255,255);
    width: 22px;
    height: 22px;
}

.switch.active {
    background-color: rgb(16,89,255);
}

.switch.active > .slider{
    margin-left: 38px;
}

.remember {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    width: 80%;
    margin: 0px auto;
    font-weight: 500;
}

label[for="remember"]:last-of-type > span {
    font-size: 14px;
    position: relative;
    bottom: 5px;
}
<div class="remember">
  <label class="switch" for="remember">
    <span class="slider"></span>
  </label>
  <input type="checkbox" name="remember" id="remember">
  <label for="remember"><span>KEEP ME SIGNED IN</span></label>
</div>

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

alignment of text output and label that responds to various screensizes

Here is some html code with a label and an output next to it. <div class="panel-body"> <div class="col-sm-6"> <label class="head6">Company Name : </label><span class="head9 halfR"> ...

What is the best way to extract basic information from a JSON object?

What is the best way to retrieve the weight value from this specific object? var prescription = "{'type':'" + $('#medi-type option:selected').val() +"',"+ "'weight':" + $('#weight').val() +","+ ...

VueJS - apply a rotation animation before showing the element

I'm having trouble displaying a line in different directions. While vertical and horizontal lines work fine, the diagonal direction requires rotation before it appears correctly. The issue is that it initially displays vertically before rotating to 13 ...

Multer is set up to save only a single file from the req.files object into the

I am in the process of developing a straightforward webpage that includes a form for uploading images and other data to a SQL Server database using Node.js, Express, Sequelize for database connectivity, and Multer for handling file uploads. While I have so ...

Error encountered in Angular production mode: JSON parsing issue at position 65 with unexpected { token

Seeking assistance with a perplexing issue I've encountered after extensive investigation. Despite my efforts, the problem remains elusive. I am working on an Angular 10 project with a PHP backend API: ... $result = array( 'status' ...

Showcasing ranges from various input types on a single page

I have a challenge in displaying the values of multiple sliders on my webpage. Here's the code snippet I've been working on: var i = 0; var st = 'slider'; var ot = 'output'; var s = ''; var o = ''; for ...

Issue with Ajax Rating Control not displaying when printing through JavaScript

I have a rating control implemented using Ajax in my aspx page. However, when I try to print the page using JavaScript, the rating control does not appear in the printed version or print preview. Does anyone have a solution for this issue? Below is the tag ...

Tips for avoiding the automatic transition to the next slide in SwiperJS

How can I prevent the next button click in swiper based on my custom logic? I am using the swiperjs library within a Vue project and I need to stop users from swiping or clicking the next button to move to the next slide depending on certain conditions de ...

Exploring the layout of an exported website in Next.js

Looking for a wizard in the world of Next.js to assist me with this query, or at least be straightforward and inform me if it is an impossible task. We have a website that is compiled into static files. These files will be hosted on S3. After running nex ...

How can we stop the page from scrolling after a click?

Upon clicking the link labeled Click Me, the page automatically scrolls back to the top. This behavior is not desired. How can I correct this issue? For example, here is a link to a relevant resource: http://jsfiddle.net/Y6Y3Z/ Regarding the scroll-bar: ...

What are the steps to design a versatile gallery page that can serve various projects?

Allow me to get straight to the point. What is my goal? I am aiming to develop galleries for various projects. Each project's thumbnail on the main page should open a gallery as a new page. These galleries will all have the same layout but different ...

What steps can be taken to customize the default keyboard shortcuts functionality in Swiper.js?

I am trying to customize the functionality for left/right keys in Swiper.js but I am unable to find a way to do this through the API () It seems that the API only allows you to disable/enable default actions: mySwiper.keyboard.enabled // Whether th ...

Triggering download of .CSV file in Angular 2 upon user click with authentication

Using a Spring Boot backend, my API utilizes a service to send data through an OutputStreamWriter. In Angular 2, I can trigger a download by clicking on a button: In Typescript results(){ window.location.href='myapicall'; } In HTML <bu ...

I am sorry, but it seems like there is an issue with the definition of global in

I have a requirement to transform an XML String into JSON in order to retrieve user details. The approach I am taking involves utilizing the xml2js library. Here is my TypeScript code: typescript.ts sendXML(){ console.log("Inside sendXML method") ...

The use of the picture element, with its ability to support various image formats and sizes, must always include

Recently, I came across a VueJS template that closely resembles HTML but has the following structure: <picture> <source type="image/avif" :scrset="avif" /> <source type="image/webp" :scrset="webp" ...

I am in search of a clean and efficient method to modify the class of a link that triggers an HTMX request in Django. Perhaps something like "auto-refresh" or a similar solution would be ideal

I've encountered an issue with HTMX in Django. The page consists of two main components: a list of categories and the content that is displayed when a category is clicked. Initially, everything was working smoothly with standard htmx functionality. H ...

Error encountered when passing arguments from code-behind to a JavaScript function

When working in the code behind: string func = "displaySuccessMessage("+name+");"; ClientScript.RegisterStartupScript(this.GetType(), "success", func, true); If in a separate JavaScript file: function displaySuccessMessage(user) { ...

Encountering a prop validation error in JSX when using an onClick event and passing a function that is not recognized as

Struggling with prop validation issue where I am encountering an error while passing a function as a prop and the error message claims it is not a function. Looking at Contact.jsx: import Avatar from "./Avatar"; import PropTypes from "prop ...

Is there a native horizontal divider available in Bootstrap 4?

Is there a predefined horizontal divider in Bootstrap 4? I currently have this: <style type="text/css> .h-divider{ margin-top:5px; margin-bottom:5px; height:1px; width:100%; border-top:1px solid gray; } </style> However, I would prefer t ...

New from Firefox 89: The afterprint event!

Having an issue with this fragment of code: const afterPrint = () => { this.location.back(); window.removeEventListener('afterprint', afterPrint); }; window.addEventListener('afterprint', afterPrint); window.print(); I&apos ...