How to change button color when radio input is selected, but input is wrapped in div before label?

kkeune

I am trying to make our dinky radio buttons into lovely toggle buttons on our donation page. The HTML cannot be modified, and as it stands the inputs are wrapped in divs, then followed by the labels. I have zero knowledge of JS/jQuery and I imagine this task requires some.

Here is my fiddle: https://jsfiddle.net/cgz63qhd/

body {
  padding: 10px;
  font-family: sans-serif;
}

div.donation-levels {
  margin: 3px 0;
}

.donation-level-container {
  display: inline-block;
}

.donation-level-container input {
  visibility: hidden;
}

.donation-level-amount-container {
  text-align: center;
  margin: 5px 2px;
  padding: 0.7em 2em;
  color: #ffffff;
  background-color: #1a92b4;
  border-radius: 5px;
  display: inline-block;
  cursor: pointer;
  font-size: 22px;
}

.donation-level-amount-container:hover {
  background: #e8525f;
  color: #ffffff;
}

.donation-level-label-input-container input:checked~label {
  background: #e8525f;
}
<div class="donation-level-container">
  <div class="form-content">

    <div class="donation-level-input-container form-input">

      <div class="donation-level-label-input-container">
        <input name="level_flexibleexpanded" id="level_flexibleexpanded5942" value="5942" onclick="evalMatchingGift('$35.00');" type="radio">
      </div>

      <label for="level_flexibleexpanded5942" onclick="">


    <div class="donation-level-amount-container">
    $35.00
    </div>

    </label>

    </div>

    <input name="level_flexibleexpandedsubmit" id="level_flexible_5942expandedsubmit" value="true" type="hidden">
  </div>
</div>
<div class="donation-level-container">
  <div class="form-content">

    <div class="donation-level-input-container form-input">

      <div class="donation-level-label-input-container">
        <input name="level_flexibleexpanded" id="level_flexibleexpanded5943" value="5943" onclick="evalMatchingGift('$60.00');" type="radio">
      </div>

      <label for="level_flexibleexpanded5943" onclick="">

    <div class="donation-level-amount-container">
    $60.00
    </div>

    </label>

    </div>

    <input name="level_flexibleexpandedsubmit" id="level_flexible_5943expandedsubmit" value="true" type="hidden">
  </div>
</div>
<div class="donation-level-container">
  <div class="form-content">

    <div class="donation-level-input-container form-input">

      <div class="donation-level-label-input-container">
        <input name="level_flexibleexpanded" id="level_flexibleexpanded5944" value="5944" onclick="evalMatchingGift('$120.00');" type="radio">
      </div>

      <label for="level_flexibleexpanded5944" onclick="">

    <div class="donation-level-amount-container">
    $120.00
    </div>

    </label>


    </div>

    <input name="level_flexibleexpandedsubmit" id="level_flexible_5944expandedsubmit" value="true" type="hidden">
  </div>
</div>

Here is my inspiration donate page: https://action.audubon.org/donate/now

Alas, their labels are set up better so I think they were able to make the buttons with pure CSS (?).

My buttons currently are looking decent, are sized fine and colored nicely, but they just won't stay that coral color when clicked! Can someone help me out?

I've seen a lot of questions here on this topic but I can't seem to get anything to work.

I'm sure there are other issues in the code, please point them out if you see them!

Huelfe

You need this piece of jQuery:

$(function() {
  $(document).on('click','.donation-level-amount-container',function(){
    $('.donation-level-amount-container').removeClass('active');
    $(this).addClass('active');
  });
});

Update also to this CSS:

.donation-level-amount-container:hover, .donation-level-amount-container.active { 
    background:#e8525f;
    color:#ffffff; 
}

Here is the updated jsfiddle.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

change radio button color when not selected

From Dev

On input focus change color of label. How?

From Dev

Change Color of Label and Div Around Input + Label on Click

From Dev

How do I add class to label when radio button is selected?

From Dev

Change div visibility when radio button becomes selected

From Dev

How to Change Input Button Font color?

From Dev

Turn on radio button with span label as input

From Dev

HTML CSS: Switch/Change background color of div, color of label text on radio button selection

From Dev

How to change a radio button selection when a specfic input field in the form is not empty

From Dev

Creating html5 placeholder from form label when input is wrapped in a div

From Dev

Creating html5 placeholder from form label when input is wrapped in a div

From Dev

How to change the value of hidden form data when a radio button is selected?

From Dev

A label tag wrapped around a radio button prevents the radio button from responding to a "change" event listener in JavaScript

From Dev

Change label CSS when child radio button is selected (without using javascript/jquery)?

From Dev

How to fire an event when a radio-button (input) is checked?

From Dev

Show div when radio button selected

From Dev

Remove Div Attribute when radio button is selected

From Dev

Showing a div when radio button selected

From Dev

How can I change a label text without interfering with an input radio inside the label?

From Dev

jQuery radio button hidden input value change

From Dev

Change label color based on user input

From Dev

Change label color based on user input

From Dev

change text-color of label on focus input

From Dev

Change color of selected option in html select input

From Dev

Change text input background color on selected exit

From Dev

How to navigate with arrow keys between radio buttons when input type radio is hidden and label is shown?

From Dev

Change color when radio button is changed

From Dev

Turning text input into bold after checbox is checked and change color after clicking radio button

From Dev

How to make radio input selected not the multiple

Related Related

  1. 1

    change radio button color when not selected

  2. 2

    On input focus change color of label. How?

  3. 3

    Change Color of Label and Div Around Input + Label on Click

  4. 4

    How do I add class to label when radio button is selected?

  5. 5

    Change div visibility when radio button becomes selected

  6. 6

    How to Change Input Button Font color?

  7. 7

    Turn on radio button with span label as input

  8. 8

    HTML CSS: Switch/Change background color of div, color of label text on radio button selection

  9. 9

    How to change a radio button selection when a specfic input field in the form is not empty

  10. 10

    Creating html5 placeholder from form label when input is wrapped in a div

  11. 11

    Creating html5 placeholder from form label when input is wrapped in a div

  12. 12

    How to change the value of hidden form data when a radio button is selected?

  13. 13

    A label tag wrapped around a radio button prevents the radio button from responding to a "change" event listener in JavaScript

  14. 14

    Change label CSS when child radio button is selected (without using javascript/jquery)?

  15. 15

    How to fire an event when a radio-button (input) is checked?

  16. 16

    Show div when radio button selected

  17. 17

    Remove Div Attribute when radio button is selected

  18. 18

    Showing a div when radio button selected

  19. 19

    How can I change a label text without interfering with an input radio inside the label?

  20. 20

    jQuery radio button hidden input value change

  21. 21

    Change label color based on user input

  22. 22

    Change label color based on user input

  23. 23

    change text-color of label on focus input

  24. 24

    Change color of selected option in html select input

  25. 25

    Change text input background color on selected exit

  26. 26

    How to navigate with arrow keys between radio buttons when input type radio is hidden and label is shown?

  27. 27

    Change color when radio button is changed

  28. 28

    Turning text input into bold after checbox is checked and change color after clicking radio button

  29. 29

    How to make radio input selected not the multiple

HotTag

Archive