Change style of a div

2

I have a div that is hidden on the screen:

 <div id="selectCity" name="selectCity" 
    class="form-group col-md-12" style="display: none;" >

    <label for="cities">Para os usuários da cidade:</label>
    <?php echo $this->formRow($form->get('cities')); ?>

 </div>

When changing the radio group selection, it should be visible. For this I use this code:

function handleClick(myRadio) {
   if (myRadio.value.localeCompare("selecteduser") === 0) { 
       document.getElementsById("selectCity").style.display = "block";
   } else {
       document.getElementsById("selectCity").style.display = "none";
   }
}

handlerClick is called, checking is done without major problems. The problem is the style of the div is not changed.

Can someone tell me why?

    
asked by anonymous 27.10.2015 / 19:29

2 answers

2
  

The following is an example, and when id is not used getElementsById uses getElementById

function handleClick(myRadio) {
   if (myRadio.value.localeCompare("selecteduser") === 0) { 
       document.getElementById("selectCity").style.display = "block";
   } else {
       document.getElementById("selectCity").style.display = "none";
   }
}
    
27.10.2015 / 19:41
1

Using jQuery

  

On the radio that will perform the show action

$("#idDoRadio").on("click", function(){
   $("#idDaDiv").show();
});
  

And in the radio that will perform the hide action

$("#idDoRadio").on("click", function(){
   $("#idDaDiv").hide();
});
    
27.10.2015 / 19:53