Having trouble making radio buttons clickable with jQuery/JS?

Having a minor issue as a beginner, I am struggling to make buttons within a DIV clickable.

The top line consists of 5 buttons that work perfectly. When clicked, a 2nd row appears as expected, but for some reason, I can't click on them. What could be causing this?

To see the code and the issue in action, check out this link: https://jsfiddle.net/yello/1me8naee/

Here is the code snippet:

       $(document).ready(function() {
                $('#div1,#div2,#div3').hide();
                $('#mod-7').click(function() {
                  $('#div1').show('fast');
                  $('#div2').hide('fast');
                  $('#div3').hide('fast');
                });
                // Other button click functions...
              });
.segmented {
  padding: 12px;
}
// CSS Styles...
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="segmented">
  <input type="radio" name="mod-1" value="Organisation" id="mod-7">
  <label for="mod-7">iPhone 7</label>
  // Other input and label elements...
</nav>

Answer №1

Your code is performing well as expected. Simply incorporate unique identifiers to the labels.

For example:

   <div id="div1">
      <input type="radio" name="mem" id="32" value="32">
      <label for="32">32Gb</label>
      <input type="radio" name="mem" id="128" value="128">
      <label for="128">128Gb</label>
      <input type="radio" name="mem" id="256" value="256">
      <label for="256">256Gb</label>
    </div>

https://jsfiddle.net/1me8naee/12/

Furthermore, ensure that the IDs are specific to each model to prevent conflicts like having "32 iPhone 6" and "32 iPhone 7."

Answer №2

Review to ensure that the ID of the radio button is included in the code snippet `for="mem3-64"` as demonstrated below.

       $(document).ready(function() {
                $('#div1,#div2,#div3').hide();
                $('#mod-7').click(function() {
                  $('#div1').show('fast');
                  $('#div2').hide('fast');
                  $('#div3').hide('fast');
                });
                $('#mod-7p').click(function() {
                  $('#div1').show('fast');
                  $('#div2').hide('fast');
                  $('#div3').hide('fast');
                });
                $('#mod-6s').click(function() {
                  $('#div1').hide('fast');
                  $('#div2').show('fast');
                  $('#div3').hide('fast');
                });
                $('#mod-6p').click(function() {
                  $('#div1').show('fast');
                  $('#div2').hide('fast');
                  $('#div3').hide('fast');
                });
                $('#mod-se').click(function() {
                  $('#div1').hide('fast');
                  $('#div2').hide('fast');
                  $('#div3').show('fast');
                });
              });
.segmented {
  padding: 12px;
}

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

.segmented label {
  border: outset 1px silver;
  padding: 2px 16px;
  margin-right: -5px;
  background: #ddd;
  cursor: pointer;
}

.segmented input:checked + label {
  border: inset 1px silver;
  background: #aaa;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js</script>
...
    </div>
    <div id="div3">
      <input type="radio" name="mem" id="mem3-32" value="32">
      <label for="mem3-32">32Gb</label>
      <input type="radio" name="mem" id="mem3-64" value="64">
      <label for="mem3-64">64Gb</label>
    </div>

  </div>

</nav>

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 causing the button on the update div to not respond when clicked after receiving a Jquery ajax response?

As a newcomer to Jquery, I am facing a challenge where I want the user to be able to select an item and have a table displayed with editable information. I expect this table to automatically update once the user clicks on the "modifier" button. The tables ...

Tips for automatically loading a new page or URL when a user scrolls to the bottom

I am working on implementing infinite scroll functionality, where a new page loads automatically when the user reaches the bottom of the page or a particular div. Currently, I have this code that loads a new page onclick. $("#about").click(function(){ ...

Verify the Javascript for file upload in ASP.NET folder prior to uploading it

Struggling with this problem for days now, I could really use some fresh perspective. My setup includes Windows Server 2012, IIS 8.0, and ASP.NET 4.5. I'm new to both IIS and ASP.NET, so please bear with me. The website I'm working on involves f ...

A Promise is returned when making multiple axios get requests in Node.js

How can multiple axios get requests be returned as a Promise? The following code shows my current approach: async function main() { const URL_1 = 'abc.com/get1/data1'; const result_1 = await getData(URL_1); const URL_2 = 'abc ...

Tips for altering the currently active tab in a separate window using a browser extension?

I'm currently working on developing a Firefox Extension and I'm facing a challenge. I'm trying to navigate to a specific browser tab in a different window. After reading through the Firefox Browser Extensions API documentation, I learned tha ...

How can we effectively map Typescript Enums using their keys without relying on a Map?

Consider the following Enum instances: export enum TopicCategories { GUIDES = 'Guides', TASKS = 'Tasks', CONCEPTS = 'Concepts', FORMULAS = 'Formulas', BLOGS = 'Blogs' } export enum Top ...

Loading images in advance with AJAX for enhanced AJAX performance

My website is structured in a sequential manner, where page1.html leads to page2.html and so on. I am looking to preload some images from the third page onto the second page. After searching, I came across this amazing code snippet: $.ajax({ url ...

Using React and TypeScript to enable file uploads

Seeking assistance in creating a basic single select upload component. When I click a button that contains a hidden input field, the file dialog opens and allows me to choose a file. The placeholder then changes to display the selected file name along with ...

PHP, having difficulty assigning value to variable using $_POST

Having a minor frustrating issue... I am transmitting a form value to PHP using AJAX, and it appears to be functioning properly. Upon performing var_dump in PHP, I can see my values and even set a variable and echo it correctly. However, this line $prod_i ...

Translating Django into JavaScript files

I tried to localize the js files following the Django documentation, but unfortunately, it's not working as expected. Here is a summary of my setup: settings.py: LOCALE_PATHS = (os.path.join(BASE_DIR, 'locale'),) urls.py in the main proje ...

Bizarre String Behavior in jQuery JSON Through Ajax Request

Something unusual is occurring: whenever I try to send the string "??" to the server using AJAX $.ajax({ type: 'POST', url: path, dataType: 'json', data: JSON.stringify({ text: "??" }) }); it consistently results in send ...

Is it possible to replace JavaScript files that are included in my index page if I am utilizing conditional comments specifically for IE9?

My website works perfectly in all browsers, except for IE9. After some investigation, I discovered that the issue lies with a jQuery plugin called multilevelpush.js. While it works great on other browsers, it simply won't cooperate with IE9. Upon fur ...

In order to manage this specific file type, you may require a suitable loader. React in conjunction with Material UI could be the

I recently created a project using Material UI and React JS, but I encountered a puzzling error without making any changes to my app. Despite reaching out for help by creating an issue on MUI, I received no response. The app was generated using npx-create ...

Transmitting data from Javascript to Django views

I'm looking to transfer data to my Django view while also redirecting the page. Since ajax seems to be not an option, I'm not sure how to accomplish this using Jquery. ...

CSS - Overlapping elements on smaller screens due to being stacked

I am encountering an issue with a column of elements stacked below each other in my code. Here is a simplified version of my implementation: <div style="position: relative; height: 100%;"> <div style="position: absolute;">Really long text h ...

trouble encountered when attempting to integrate typeahead functionality in AngularJS using jQuery

Greetings! I am brand new to using AngularJS and currently exploring the implementation of typeahead functionality. I decided to utilize an existing library by including the following script: <script src="lib/xyz/typeahead.bundle.js"></script> ...

What is the best way to execute methods once subscription data is received?

Exploring the most effective way to execute multiple methods when new data arrives from an Observable, such as an HTTP request, and those methods need to be called with the data. I have been experimenting with two different approaches, but I find drawback ...

Adding the output from a promise to an array

I am attempting to clear out and then refill an array with values retrieved from a promise. However, I've noticed that the values don't always get added back in the same order. $scope.$watch ('timeRange', function (newValue, oldValue, ...

Is it possible to remove certain 'css-' class names that MUI automatically applies to its components? (Using Next JS and MUI)

After successfully migrating my create-react-app project to Next JS using the latest version (12.1.0) and following the migration guide at https://nextjs.org/docs/migrating/from-create-react-app, I encountered an unexpected issue. Despite still using MUI a ...

Creating links within a single image in HTML?

Is there a way to hyperlink different parts of a single image to various webpages using JavaScript coordinates or any other method? ...