javascript - ".check" for radio in JS -
here's code:
document.getelementbyid("frequencyweekly").checked = function() { document.getelementbyid("newsoptions").classname = "activesubscription"; }; <div id="newsoptions"> <input type="radio" id="frequencyweekly" name="newsletterfrequency"> <label for="frequencyweekly">weekly</label> <input type="radio" id="frequencymonthly" name="newsletterfrequency"> <label for="frequencymonthly">monthly</label> </div>
i .newsoptions div have class .activesubscription if #frequencyweekly button checked. how should that?
checked
boolean, not event fires function, want
if ( document.getelementbyid("frequencyweekly").checked ) { document.getelementbyid("newsoptions").classname = "activesubscription"; }
if want in event handler be
var box = document.getelementbyid("frequencyweekly"), elem = document.getelementbyid("newsoptions"); box.addeventlistener('change', function() { if ( this.checked ) { elem.classlist.add("activesubscription"); } else { elem.classlist.remove("activesubscription"); } }, false);
Comments
Post a Comment