javascript - Style <li> if radiobutton is checked - Howto? -
i trying style <li> wether radiobutton checked or not.
here plugin code trying alter:
<div class="gift-certificate-show-form"> <p><?php _e( 'vem vill du skicka ditt presentkort till?', 'wc_smart_coupons' ); ?></p> <ul class="show_hide_list" style="list-style-type: none;"> <li> <input type="radio" id="hide_form" name="is_gift" value="no" checked="checked" /> <label for="hide_form"> <?php _e( 'skicka presentkortet till mig!', 'wc_smart_coupons' ); ?> </label> </li> <li> <input type="radio" id="show_form" name="is_gift" value="yes" /> <label for="show_form"> <?php _e( 'till nĂ¥gon annan!', 'wc_smart_coupons' ); ?> </label> </li> </ul> </div> how go make happen?
i tried: `
show_hide_list input[type="radio"]:checked + label { background: beige !important; but backgrounds text. want entire <li> highlited. thanks
this possible in css 4, using :has selector, in jquery. however, of now, no browser implements it, you'll have use javascript (jquery job)
here's code, add highlighted css class style:
$(".gift-certificate-show-form :radio").on("click", function() { $(this).closest(".gift-certificate-show-form").find("li").removeclass("highlighted"); $(this).closest("li").addclass("highlighted"); }); another way job, noticed form starts checked radio:
$(function() { var updatehighlight = function() { $(".gift-certificate-show-form") .find("li") .removeclass("highlighted") .end() .find("li:has(:radio:checked)") .addclass("highlighted"); }; updatehighlight(); $(".gift-certificate-show-form :radio").on("click", function() { updatehighlight(); }); }); fiddle here: http://jsfiddle.net/lucastrz/yc6qj/1/
don't forget add reference jquery.
Comments
Post a Comment