kiasati kiasati - 6 months ago 30
CSS Question

changing the style of an input element's parent

i wanna change the parent's style of an input element, when its checked

<div> <!--- this is the parent element --->
<input type="radio" data-dynamic-update="1" name="virtuemart_paymentmethod_id" id="payment_id_3" value="3" checked="checked">

i found this after googling:

var x = document.getElementById("payment_id_3");
x.addEventListener("click", function(){
$(x).parent().css({"background-color": "green", "border": "1px solid green"});

but it doesn't work.. how can i do this?


If you want Enable + Disable values, this is probably what you are looking for:

    if (this.checked === true) { //Checked CSS
                'background-color': 'green',
                'border': '1px solid green'
        else  {         // unchecked CSS
                                'background-color': 'red',
                        'border': '1px solid black'

NOTICE: I've changed the "radio" to a checkbox.