Detecting changes in radio button selections through SVG animations

My goal is to trigger an SVG animation when a user selects a specific radio button. The idea is that the value of the radio button should match the ID of the animation. Below is a simplified explanation of the process.

Whenever a user clicks on a radio button, all other radio buttons with the same name should have either a green or blue background: blue if it's selected, and green if it's not.

$('input[type="radio"]').change( function(){

    var $scribbleSelectorName = $(this).attr('name');
    var $scribbleSelectorInputs = $("input[name=" + $scribbleSelectorName + "]");

    $($scribbleSelectorInputs).each(function(){


        if ($(this).prop("checked")) {
            $(this).css("background","green");
        }

        else {
            $(this).css("background","blue");
        }

    });

});

You can view a demo here. I've gone through various similar problems, but none of the solutions seem to be effective.

Answer â„–1

Your background changes are effective, but not visible. I have updated them to highlight the parent element, which is represented by <li>.

$(this).parent().css("background","green");

I also made a modification from $(this).attr("checked") to $(this).prop("checked").

In response to the second part of your query, you can implement an animation like this:

$('input[type="radio"]').change( function(){
    var $scribbleSelectorName = $(this).attr('name');
    var $scribbleSelectorValue = $(this).attr('value');
    var $image = $('<img/>', {
        'src': imagesMap[$scribbleSelectorName][$scribbleSelectorValue]
    });
    $('.svg-container.' + $scribbleSelectorName).empty().append($image);
});

var imagesMap = {
    test: {
        'A': 'http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/acid.svg',
        'B': 'http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/adobe.svg',
        'C': 'http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/alphachannel.svg',
        'D': 'http://dev.w3.org/SVG/tools/svgweb/samples/svg-files/android.svg'
    },
    anotherGroupOfInputs: {
        //...
    }
};

Check out the DEMO here.

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

The data entered is not being forwarded to the firebase database

I am working on an angular material form in my project. The file I am working on is add-beer.component.html <mat-form-field> <input type="number" name="mSladu" matInput placeholder="Hmotnosť sladu" #beerMSLadu="ngModel" [(ng ...

Struggling to position divs within a container div in a React component

Looking for help with aligning the divs with blue borders at the top? I need CSS code to achieve this. I tried using margin but it didn't work as expected. Also, when more content is added inside these divs, they seem to expand from the bottom to the ...

With Bootstrap 4 navigation bar, once a container is added, the elements will automatically align to the right

Greetings! I am a newcomer to the world of bootstrap, so please bear with me if my question seems too basic. My current challenge involves creating a navbar using bootstrap. However, I have encountered an issue where the logo remains on the left side whi ...

I am interested in retrieving an array

Here is the array I am working with { Colors: 'Blues', Department: 'Clearance', Size: [ 'Runners', 'Custom Sizes' ], Shape: 'Round', Designer: 'B. Smit', } The desired output should be ...

Does Ajax XMLHttpRequest trigger the execution of servlet doFilter?

I've implemented an AJAX call from a JSP page as shown below: <head> <script> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, ...

What is the best way to generate an array or multiple arrays dynamically using JavaScript?

I am currently working on a project where I need to dynamically create arrays to store elements based on certain conditions. Specifically, I want to create an array for each occurrence of a specific element (in this case, "bank"). The first occurrence shou ...

Having trouble with imgareaselect in jQuery?

imgareaselect seems to be having issues with allowing a selection. The buttons in the editor box are not functioning properly. It's unclear whether it's not receiving my string correctly or not. I suspect it has to do with my java code, but pinpo ...

Can a directive be designed to function as a singleton?

Our large single page app includes a directive that is utilized in various locations across the page, maintaining its consistent behavior and appearance each time. However, we are experiencing an issue with this directive due to the ng-repeat it contains, ...

Issues with functionality of React/NextJS audio player buttons arise following implementation of a state

I am currently customizing an Audio Player component in a NextJs application using the ReactAudioPlayer package. However, the standard Import Next/Audio and using just <Audio> without props did not yield the expected results. The player functions as ...

Iframe navigation tracking technology

Let's say I have an iframe element in my HTML document. <html> <body> This is my webpage <button> Button </button> <iframe src="www.example.com"></iframe> </body> </html> If a user clicks on links wi ...

Zoom in to see the header spanning the entire width of the page

http://jsfiddle.net/CPSKa/ Whenever I zoom in on the header of my website, the line underneath it starts to shrink. Is there a way to prevent this from happening? Here is the HTML Code: <div id="main_header"> <div id="main_header_wrapper"&g ...

Issues with Font-Face Implementation

Hey there! I'm currently working on incorporating a new font into my website using font-face. However, it seems like something might be missing from my code because the style isn't being applied correctly. Here is what I have so far: <div id= ...

Having trouble with an unresponsive AJAX form plugin by Malsup

Attempting to implement AJAX functionality in my contact form using JQuery Validation along with Malsup's AJAX form plugin, but encountering issues with the form submission when AJAX is enabled (works fine without it). As a beginner in JavaScript, I a ...

Live updates are shown in a format similar to a friend feed or the top tweets on Twitter

I'm currently utilizing PubSubHubbub to obtain the latest updates from the feed. Once the callback URL receives an update, it should be displayed on the webpage in a format similar to Friend Feed or Twitter's top tweets (with content moving down ...

Adjust the z-index of the Y-axis border in ApexCharts to position it behind the marker

https://i.sstatic.net/LS68G.png Struggling to ensure the y-axis border stays behind the marker, any assistance would be appreciated. Explore it on CodeSandbox : https://codesandbox.io/s/apexcharts-forked-znw38y?file=/src/index.js ...

Tips for maintaining video height consistency while adjusting its attributes

When you click on a button, the video's poster and src attributes change. However, after clicking, the video height briefly becomes 0, causing an unsightly effect on the entire page. How can this be avoided? Please note - lorem.mp4 and ipsum.mp4 hav ...

A guide on resetting an Angular 4 sub component

As I develop my angular web app, I have integrated a navbar and sidebar component using their respective selector tags to render them in the app.component.html. In addition, there is a login component that utilizes <router-outlet></router-outlet&g ...

How can I retrieve the current value of a text element using jQuery?

Having an issue with my text input element where an event is triggered on blur and when the user presses enter. The problem arises when the user inputs "foo" and presses enter; the val() function returns null initially, but after the blur event, it return ...

Script malfunctioning across various Heroku pages

Recently, I encountered an issue with my Rails 4 app while deploying it to Heroku. The asset pipeline was minifying the js file and everything seemed fine during development. However, after pushing it to Heroku, I noticed that the js file only worked on ce ...

The text outside of the button is overridden by my CSS styling

I've been working on a simple card matching game and I decided to style the buttons to enhance their appearance. However, I'm facing an issue where the styling code has caused the text to appear outside of the button. Whenever I try to adjust the ...