skip to Main Content

i want to remove class from others radio buttons when i click on radio button in another section with jQuery( used in oxygen builder wordpress).

jQuery(document).ready(function(){
  jQuery("div").click(function(){   
    jQuery("div.volba-1-1 div, div.volba-1-2 div, div.volba-1-3 div").removeClass("ff_item_selected");
  });
});

This works fine for me, but if i click somewhere else radio button is still selected but class was removed. Someone help me with this?

website to see my problem:
enter link description here

Image description

Thanks

2

Answers


  1. I really couldn’t understand the question, but you should use the click event for the radio buttons only, and not for every div of your page. This line is causing the undesired behaviour:

    jQuery("div").click(function(){   
    

    If there’s any other div on your page and you click it, your function will be triggered. That function should only be triggered when you click on your radio buttons, which you could easily group by using a common class amongst other ways. Then your function should look like this:

    $("div.commonClass").click(function(){
    

    Assuming that they all have this "commonClass" class.

    Login or Signup to reply.
  2. I really couldn’t understand the question, but you should use the click event for the radio buttons only, and not for every div of your page. This line is causing the undesired behaviour:

    jQuery("div").click(function(){   
    

    If there’s any other div on your page and you click it, your function will be triggered. That function should only be triggered when you click on your radio buttons, which you could easily group by using a common class amongst other ways. Then your function should look like this:

    $("div.commonClass").click(function(){
    

    Assuming that they all have this "commonClass" class.

    EDIT:

    First, you need to make your desired div’s members of a common class:

    <div class="commonClass someOtherClass"> //first div
    <div class="commonClass"> //2nd div
    //and so on!! just add "commonClass" to these div's
    

    Then in your JQuery code:

    $("div.commonClass").click(function(){
        $("div.commonClass").removeClass("ff_item_selected"); 
        //this line will remove ff_item_selected class from all your divs (the ones who are members of commonClass)
        
        $(this).addClass("ff_item_selected");
        //this line will add the ff_item_selected class only to the item that was clicked.
    });
    

    And that’s it!! with those 2 lines you’ll always have only your selected item with the class ff_item_selected. $(this) keyword will help you a lot when coding in JQuery.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search