Is it feasible to automatically uncheck all the other checkboxes when one checkbox is checked in HTML?

Currently, I am in the process of constructing a gallery using pure CSS. When I select image1, checkbox1 will be checked and div1 will become visible. This functionality has already been implemented successfully. However, an issue arises when I click on image2, causing div2 to appear. Subsequently, if I click on image1 again, div1 does not reappear due to div2 overlapping it.

HTML:

<div class="gallery">
<label for="toggle1"><a>1</a></label>
<input id="toggle1" type="checkbox">
<label for="toggle2"><a>2</a></label>
<input id="toggle2" type="checkbox">
<label for="toggle3"><a>3</a></label>
<input id="toggle3" type="checkbox">
<label for="toggle4"><a>4</a></label>
<input id="toggle4" type="checkbox">
<label for="toggle5"><a>5</a></label>
<input id="toggle5" type="checkbox">
<label for="toggle6"><a>6</a></label>
<input id="toggle6" type="checkbox">
<label for="toggle7"><a>7</a></label>
<input id="toggle7" type="checkbox">
<label for="toggle8"><a>8</a></label>
<input id="toggle8" type="checkbox">
<div class="conteudo1">1</div>
<div class="conteudo2">2</div>
<div class="conteudo3">3</div>
<div class="conteudo4">4</div>
<div class="conteudo5">5</div>
<div class="conteudo6">6</div>
<div class="conteudo7">7</div>
<div class="conteudo8">8</div>
</div>

I have omitted the CSS code since I struggled with automatically indenting it, but you can view it here.

Essentially, my goal is to uncheck all other checkboxes when checkbox1 is selected, and repeat this behavior for the remaining checkboxes.

I was never particularly fond of Javascript, but surprisingly managed to achieve this task within 10 minutes. Nevertheless, I am curious if there are alternative methods to accomplish the same outcome.

Thank you for your time!

Answer №1

A solution would be to incorporate JavaScript code that deselects the other checkboxes when one is checked. It's worth noting that HTML has a comparable feature with radio buttons, as pointed out by mu is too short

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

What is the best way to divide a string into an array containing both linked and non-linked elements?

I'm struggling to find the right solution to my problem. I need to create a view that is enclosed in a clickable div. The content will consist of plain text mixed with clickable URLs - the issue arises when clicking on a link also triggers the method ...

"Unveiling the power of canvas layers in creating dynamic

Curious about the process of achieving this task. Draw, pause for 1 second. Draw frame 2, pause for 1 second. Draw frame 3, pause for 1 second. Clear animation canvas. I believe the solution involves working on an overlapping canvas to avoid being erased ...

Optimizing the Functionality of jQuery Modal Windows

I'm struggling to make it so that every time the arrow is pressed, the content shifts accordingly. Currently, it only displays the content for: <div id="dialog" class="window"> One <a href="#"class="close"/>Close it</a> </div> ...

Is there a way to retrieve the content of a WordPress page minus the HTML tags?

$content = fetch_content(); var_dump($content); <figure class="wp-block-gallery columns-1 is-cropped"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><img src="http://www ...

Creating a designed pattern for a textbox: Let's get creative with your text

How can I create a Textbox that only allows numeric values or the letter 'A'? <input type="text" id="txt" name="txt" pattern="^[0-9][A]*$" title="Allow numeric value or only Letter 'A'&quo ...

Is there a way to adjust the height of a DIV based on the background image and keep the text centered at the same time?

Currently in the process of designing a landing page for my website, and I am interested in incorporating a Jumbotron to provide a more modern and tech-savvy touch. Successfully managed to center my text both horizontally and vertically, now looking into s ...

Is it possible to smoothly transition from one background image to another in CSS or JavaScript?

Most tutorials I've come across suggest using a background image with a linear gradient overlay, but that solution doesn't suit my needs: I have two adjacent divs with background images, slightly overlapping by 50px. I wish to create a gradient ...

Utilize CSS to incorporate special characters as list markers

Is there a way to use CSS to make the list marker in an HTML list display as "►"? ...

Prevent unexpected page breaks in <tr> elements on Firefox (Could JavaScript be the solution?)

Wondering if there are any ways, possibly through JavaScript or CSS, to avoid having page breaks within <tr> elements specifically in Firefox. Given that FF does not yet fully support page-break-inside, I assume this might need to be addressed using ...

Twitter Bootstrap navbar-collapse can be seen overlapping navbar-header section, causing a

I seem to be having a problem with the Twitter Bootstrap navbar-collapse element overlapping the navbar-header logo, 'the alpha', and causing the link to be unclickable. As shown in the image below, the alpha logo has an href link but is not cli ...

Is there a way to utilize the reset() function within an input form?

Is there a way to automatically reset the textbox when submitting a value? Below is my code: <!DOCTYPE html> <html> <body> <ul id="myList"> </ul> <input type="text" id="myText" value="&q ...

Steps for adding a stroke to just the left and right sides of an SVG wave:

How do I apply a stroke only to the right and left sides of an SVG (specifically a wave SVG)? <svg class="defs-only" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <symbol id="wave"> <svg viewBox="0 0 100 50" ...

Challenges arising from the offset in an overflowing Div

Encountering issues with JQuery Offset when utilized within a div that has a fixed height and overflow. This particular div contains two columns, a main column and a sidebar. The objective is to have one of the sidebar divs scroll within its container unt ...

Creating a responsive design using Bootstrap4

Today, I made the switch to bootstrap4 and enabled flexbox in _variables.scss. However, I'm still confused about the flexbox capabilities of bootstrap4. Some questions I have include: How can I utilize flex-direction:column? Is it possible to creat ...

Creating a universal function to handle setTimeout and setInterval globally, inclusive of clearTimeout and clearInterval for all functions

Is it possible to create a universal setTimeout and setInterval function with corresponding clearTimeout and clearInterval for all functions while passing values to them? The situation is as follows: 1. More than 8 functions utilizing setInterval for act ...

Numerous categories housed within various div containers

I am working with an HTML code that contains 6 different div elements: <div class="hisclass1 hisclass2 myclass hisclass3"> <div class="herclass1 herclass2"> <!-- 2nd div --> </div> </di ...

Filter Products with Magento Layered Navigation - Checkbox Options

Is there a method to transform the layered navigation into checkboxes similar to Asos? I have noticed that there are modules available for purchase claiming to offer this functionality. I may consider using one of those, but I wanted to explore any other ...

Update the radio button to display the value entered in the text input field

I'm trying to implement a feature where the value of a text box can be set as the value of the selected radio button. Below is the code I have: HTML <form action="add.php" id="registration" method="post" name='registration' onsubmit="re ...

Is there a requirement to download and set up any software in order to utilize Highchart?

I've been working on a project to create a program that displays highcharts, but all I'm getting is a blank page. Here's my code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charse ...

Finding a solution for odd css box-sizing behavior in Bootstrap 3 and eliminating the unwanted horizontal slider

My website built with Bootstrap 3 looks great in Internet Explorer, but in Chrome and Firefox there seems to be a persistent bottom slider and a small area on the right side that remains visible even when I scale down to 1%. I suspect this issue is relate ...