"Clicking on the radio button does not activate when placed within an <a> tag

Why is it that when the text is clicked, the radio button is checked, and when the little green patch is clicked, the frame is working, but they both don't work at the same time? Any assistance in resolving this issue would be greatly appreciated.

body {
  user-select: none;
}

a {
  text-decoration: none;
  margin: 10px;
  color: #000;
  background: violet;
}

label {
  background: yellowgreen;
}

input[type="radio"] {
  display: none;
}

input[type="radio"]:checked+a>label {
  color: red;
}
<input type="radio" name="list" id="1" />
<a href="Text1.html" target="frame">
  <label for="1">text</label>
</a>
<input type="radio" name="list" id="2" />
<a href="Text2.html" target="frame">
  <label for="2">text</label>
</a>
<input type="radio" name="list" id="3" />
<a href="Text3.html" target="frame">
  <label for="3">text</label>
</a>
<iframe name="frame"></iframe>

Answer №1

Is including some JS the solution?

You have the option to eliminate the radio buttons here

const labels = [...document.querySelectorAll("#nav label")];
const iFrame = document.querySelector("iframe");
document.getElementById("nav").addEventListener("click", function(e) {
  const label = e.target.closest("label");
  if (label) {
    labels.forEach(label => label.classList.remove("checked"));
    label.classList.add("checked");
    iFrame.location = `text${label.id}.html`
  }
})
body {
  user-select: none;
}

label {
  text-decoration: none;
  margin: 10px;
  color: #000;
  background: yellowgreen;
}

span {
  background: violet;
}

input[type="radio"] {
  display: none;
}

.checked {
  color: red;
}
<div id="nav">
  <label id="1" />text<span>&nbsp;</span></label>
  <label id="2" />text<span>&nbsp;</span></label>
  <label id="3" />text<span>&nbsp;</span></label>
</div>
<iframe name="frame"></iframe>

Answer №2

Here is a snippet of code you can use:

<a href="Page1.html" target="content">
  <input type="checkbox" name="items" id="item1"/>
  <label for="item1">Item 1</label>
</a>
<iframe name="content"></iframe>

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

Ensure that the div automatically scrolls to the bottom when it is loaded, and also when new data is added - using angular

My goal is to replicate the functionality of the iPhone's "Messages" app on a web application using AngularJS or any other JavaScript framework. Each message will be contained in a div element within a larger container. When a new message is added, I ...

In Visual Studio Code, beautification feature splits HTML attributes onto separate lines, improving readability and code organization. Unfortunately, the print width setting does not apply

I have done extensive research and tried numerous solutions, When using Angular and formatting HTML with Prettier, it appears quite messy as it wraps each attribute to a new line, for example: <button pButton class="btn" ...

Page design ruined as a result of oversized fonts in IE9 for <h2> elements

Everything looks great on various browsers, except for the notorious IE9. We've implemented a block-style layout with a width of 660px, centered on the page. Despite setting the h2 width to 660px to match the layout, IE9 displays the font size much ...

Show a dynamic Swiper carousel upon selecting a thumbnail in an image gallery

I am in the process of creating a thumbnail gallery that includes a slider feature using Swiper. The default setup has the slider hidden, and once an image is clicked, the slider should appear with the selected image. To close the slider and return to the ...

Storing multiple values of dynamically added elements in a single variable and accessing them within a function

Is it possible to store multiple values into a single variable and then access them in a setTimeout function? $(document).ready(function (){ div ({'div':'#noo','auto':'true','pos':'top',' ...

Implementing Ajax to display autocomplete suggestions in an HTML table

I've been working on implementing an ajax auto complete function into my HTML code. My goal is to display the results from the auto complete function in a table on the html page. Although the auto complete function is working and I can see the drop do ...

Resolved issue with navigation bar no longer overlapping certain sections of the website

I am in the process of creating a website that will serve as a showcase for my resume and portfolio. However, I am facing an issue with my fixed navigation bar not overlapping certain elements on the page, such as an image and progress bars, when I scroll ...

When coding on Github pages, the behavior of code blocks can vary depending on whether

I am interested in obtaining the offline version, which can be seen here: https://i.sstatic.net/NKFSQ.jpg On the other hand, the online version has a different appearance: https://i.sstatic.net/133gH.jpg If you want to view the incorrect version, click ...

React component with element style declared in module.css file and conditional state

I'm in the process of developing a mobile dropdown feature for a React web application. I am looking for guidance on the proper syntax to use when incorporating multiple classes into a React element. My goal is to apply styles from an imported module ...

Bootstrap toggle feature malfunctioning, unable to hide element

I've been working on this code and experimenting with different approaches. $('#paired-results').on('show.bs.collapse', function () { $('.callToAction').collapse('hide'); }); $('#paired-results').on( ...

Maximizing the efficiency of critical rendering path while utilizing bootstrap

Is it feasible to enhance the critical rendering path (like Google and Facebook) while utilizing Bootstrap 3? Facebook opted for inlining styles connected to the header and sidebars. Meanwhile, Google inlined all styles since they have minimal styles for ...

Does CSS media query "@media only screen" only work when I am resizing the window?

I recently encountered an issue with the code found on this website (the repository can be viewed on Github here): @media only screen and (max-width: 600px) { img {width: 100%; height: 100%; margin: 0; padding: 0; } a.box { width: 100%; pa ...

"Unfortunately, SimplyScroll isn't functioning properly on this particular page

What is the reason for simplyscroll not being able to handle this div with nested divs? EXTRA INFORMATION The scrolling functionality does not work. Clicking on the buttons doesn't trigger any scrolling. Changing the contents of the div to plain tex ...

AngularJS users are experiencing issues with the "See More" feature not functioning as expected

One of my tasks involves dealing with a block of text that needs to be truncated using ellipsis. To achieve this, I am utilizing jquery dotdotdot. For more information on dotdotdot, please refer to the documentation. I have created a straightforward dire ...

Fluid percentage-based layout

I have four separate Divs that I would like to position on my page in a specific layout. Here is an image showing how I want them positioned: https://i.sstatic.net/KBZ1U.png In the future, I plan to add multiple svg files to Div 4 and I want it to be scro ...

Display only the static placeholder in Angular 2 multi-select feature

My experience with angular 4 is fairly new and I've recently delved into using the angular multiselect feature with the npm package available here. I've managed to successfully configure it, as well as capture selected and deselected items/event ...

What could be causing the bottom of a vertical scroll bar to be cropped in Internet Explorer 11?

I am experiencing an unusual problem in IE11 where the content at the bottom of my page is being cut off along with the scroll bar that should allow for viewing that content. I have managed to resolve this issue in Chrome, Firefox, and Edge but I cannot se ...

Discovering an element within an HTML response using jQuery AJAX

Check out the code snippet below: ajax_obj = $.ajax( { data: data, success: function(answer) { console.log(answer); console.log($('#table_conferences_tbody', answer).html()); ...

Introducing a pause in the function while rendering objects

After inserting setInterval into the code, it is causing all lasers to be delayed by one second. I am looking to have them fired in this order: - initially fire laser1 and laser2. - then take a 1-second break before firing another set of lasers, a ...

Calculating the size of grid thumbnails or items using the calc() function

I am currently working on building a responsive portfolio grid that spans the full width of the screen. To achieve this, I have set the width of the items using calc() and ensured that the thumbnail image fills the entire div by applying the following CSS: ...