javascript Hide/show div on checkbox: checked/unchecked

前端 未结 4 1633
我寻月下人不归
我寻月下人不归 2020-12-19 19:24

I am trying to make a function in javascript, that will hide / show particular div in my registration form, depending on the state of my checkbox (checked or not). Here is

4条回答
  •  抹茶落季
    2020-12-19 19:49

    You should write it like this :

    function doruc() {
    var elem = document.getElementById('powermail_fieldwrap_331');
        if (document.getElementById ('powermail_field_doruovaciaadresa2_1').checked) {
        elem.style.display='block';
        } else {elem.style.display='none';}}
    

    and regarding your second question, you can either write in the div tag style="display:none" or you can do as you said (add a class for the element).

提交回复
热议问题