Modify the class of rows in table 2 once a particular value of a radio button in table 1 has been selected

One issue I am facing is related to two tables with radio buttons. Each table highlights the corresponding row when a radio button is checked, working independently. However, I need a specific value from table 1 to un-highlight any previously checked rows in table 2. Either ID "1E" or the value "Fixed Income" from table 1 should remove the highlight from table 2.

$('input[name="radio1"]').click(function() {
    $(".checked").removeClass("checked");
    if($(this).is(':checked')) {
        $(this).closest('.highOption').addClass('checked');
    }
});    

$('input[name="radio2"]').click(function() {
    $(".checked2").removeClass("checked2");
    if($(this).is(':checked')) {
        $(this).closest('.highOption').addClass('checked2');
    }
});    

// Various attempts were made to achieve this, but without success.
$('input[value="Fixed Income"]').click(function() {
    $(".checked").removeClass("checked");
    $(".checked2").removeClass("checked2");
});
.checked {
    background-color:rgba(242,242,242,0.5)
}
.checked2 {
    background-color:rgba(242,242,242,0.5)
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
   ...
</table>


<br><br>

<table>
    ...
</table>

Answer №1

Give this a shot :

$('input[name="radio1"]').click(function() {
        $(".checked").removeClass("checked");
        if($(this).is(':checked')) {
            $(this).closest('.highOption').addClass('checked');
        }
    });


    $('input[name="radio2"]').click(function() {
        $(".checked2").removeClass("checked2");
        if($(this).is(':checked')) {
            $(this).closest('.highOption').addClass('checked2');
        }
    });


    $('input[value="Fixed Income"]').click(function() {
        $(".checked").removeClass("checked");
        $(".checked2").removeClass("checked2");
    });

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

Is it possible for HTML/CSS to automatically adjust content size to fit or fill a container?

I'm interested in finding a CSS-only technique that can ensure content within a container scales to fit, regardless of whether it's text or images. Take a look at the example below: .container { display: inline-block; width: 2in; hei ...

How can I create clickable table entries using php and html?

I want to create a table on this page that is clickable. When the user clicks on a row, the data from that row will be sent to a PHP file with a form prepopulated with the selected user's information for updating purposes. <!DOCTYPE html> &l ...

How can I customize the appearance of the container and items in a dropdown <select> menu?

Im using contact form 7 on wordpress, i don't want to use a plugin rather use plain css/js to bring the results if possible. Something like this : https://i.stack.imgur.com/VTWRg.jpg ...

Submitting a specific group of form inputs using ajax involves selecting the desired elements within the form

My task involves dealing with a large form that needs to be submitted in PHP, which poses a challenge due to the maximum input variable limits in PHP +5.3 as discussed on this Stack Overflow thread. Instead of submitting everything from the form, I only n ...

Identifying Changes with jQuery Event Listeners

I am trying to run some javascript code that is in the "onchange" attribute of an HTML element. For example: <input id="el" type="text" onchange="alert('test');" value="" /> Instead of using the onchange attribute, I want to trigger the e ...

Modifying the Color of Individual Items within the Pagination Component in MUI

I am attempting to modify the background color of every item in my Pagination component by utilizing makeStyles. import { Pagination } from "@material-ui/lab"; import { makeStyles } from "@material-ui/core"; const pagination = makeStyl ...

What are the steps to adjust image size using CSS in an email signature?

Having trouble with my email signature. It appears fine on my end, but when the recipient replies, the images are oversized and the css is not rendering correctly in their response. I'm puzzled as to why this is happening. Here's the code snippe ...

No data is being returned by the Jquery Ajax function

I am experiencing an issue with a Jquery Ajax call in my code: $('body').on('click', '#btnPopulate', function() { alert(getTree()); }); function getTree() { var url = getUrlPath() + "/StoryboardAdmin/BuildStoryboardViewMode ...

Platform designed to simplify integration of high-definition imagery and scalable vector illustrations on websites

In the ever-evolving world of technology, some clients support advanced features like svg while others do not. With the rise of high resolution devices such as iPhone 4+ and iPad 3rd gen., it has become crucial to deliver graphics that can meet these stand ...

Use Angular to update the text input value

I am currently working with a basic input that is showing a timestamp in milliseconds, which is stored on the scope. However, I am interested in having it display formatted time without needing to create a new variable. I am exploring a potential solutio ...

Steps to Activate a Hyperlink for Opening a Modal Dialogue Box and Allowing it to Open in a New Tab Simultaneously

I am currently working on a website project. Within the website, there is a hyperlink labeled "View Page". The intention is for this link to open the linked page in a modal dialog upon being clicked. Below is the code snippet that I have used to achieve t ...

Enhance jQuery event handling by adding a new event handler to an existing click event

I have a pre-defined click event that I need to add another handler to. Is it possible to append an additional event handler without modifying the existing code? Can I simply attach another event handler to the current click event? This is how the click ...

Best practices for refreshing the HTML5 offline application cache

My website utilizes offline caching, and I have set up the following event handler to manage updates: applicationCache.addEventListener('updateready', function () { if (window.applicationCache.status == window.applicationCach ...

Is it recommended to use the "hasClass" function prior to implementing the "addClass" function?

Upon stumbling upon this specific code snippet, I noticed that it checks if an element has the class a, and if not, it adds it: if (!$("div").hasClass("a")){ $("div").addClass("a"); } Since jQuery doesn't add the class if it's already presen ...

Error Encountered in jQuery UI SelectMenu

Struggling to integrate the jQuery UI SelectMenu, I keep encountering the same error in the browser console. Below is the HTML Code: <select name="files" id="files"> <optgroup label="Scripts"> <option value="jquery">jQuery.js</ ...

Tips on making the form validation script operational

After developing a form alongside a form validation script to ensure that all fields are completed, the name and city sections only contain letters, while the age and phone sections solely include numbers, issues have arisen. It seems that despite the cons ...

Steps for creating a basic table filter using jQuery

What is an efficient way to create a basic table filter using jQuery without pagination requirements? I want to retrieve data from a database and display it as a list. I would like to avoid using plugins and instead opt for concise code snippets. For ...

Tips for decreasing Vuetify Grid column width on larger screens

I'm currently utilizing the vuetify grid system to construct a reply component. The column ratio is set at 1:11 for the icon and reply columns, respectively. Below you'll find the code snippet: <v-row justify="center" class="ma-0 pa-0"> ...

Developing a PHP foreach loop that integrates seamlessly with a W3 responsive grid

Is there a way to generate multiple sets of three columns using w3.css and a foreach loop to fill each set with data from a sample database? Attempted code resulted in all the columns being in a single row: <?php foreach ($products as $index => $pro ...

What is the best way to pick out specific passages of text

I'm attempting to create an autocomplete feature where the data is displayed in a div below the text box as the user types. While this typically involves ajax, I've simplified the approach without using jQuery autocomplete. Once the text appears ...