Relative Content

Tag Archive for javascripthtmlcssdom

How do I change background color of a toggle switch with javascript?

I was creating a library project, every book is a object with properties title, author, pages, and read-status stored in a array.
There’s a add-book button which opens a modal and asks the user the title, author, pages of the book they want to add and there’s a check-box for read-status.
A checked checkbox returns a true value to the book-object and an unchecked checkbox returns false.
So on to the screen, in the interface the read-status is a toggle switch. Which the user can toggle to update his read-status of the book, so I want to change the backgorund color of that switch according to the user. The bgColor is blue or red according to true and false values of read-status respectively. And the user should also able to change the read status to true or false in book-object stored in the library by toggling the switch from the screen.

How to find value of 3 inputs

I’ve created a form that pops up and now I want to store the input values in 3 separate values in the array const book.

Can’t select a class of a div element and add another class to this element [JS]

I am working on this GPS project and I ran into a problem. I wanted to build a grid of 360×180 grid-items each and each grid-item represents one single GPS coordinate, which dynamically gets a own very specific class so that I can identify the coordinate later and work with it. Unfortunately the browser returns me this Error message: TypeError: Cannot read properties of null (reading ‘classList’).

Right way to use EventListener in JS

The most suitable method that comes to my mind is to set up a single global event listener on the HTML page, which will trigger different functions based on which element is clicked. Then, within this event listener, you can utilize a switch case to determine which element was clicked and execute the corresponding function, or do nothing if a blank area is clicked.

How to display dom elements through a function that works onsubmit?

I am making greeting cards with user input using Javascript and CSS. I need to be able to have the information that the user submits in the form populate as a card underneath. I have some CSS assigned though this isnt the issue currently. I have a lot of the javascript bones there but I cant figure out how to return those elements once submitted.