Execute two functions with onclick

2

I need to run two functions with onClick, but I'm not getting it, could anyone help me? I want to hide the parent div "introductionAds" and show the "showID" div

function ocultar(ocultarID){
    document.getElementById(ocultarID).style.display='none';
}
function mostrar(mostrarID){
    document.getElementById(mostrarID).style.display='block';
}
.disabled {
  text-decoration: none;
  color: gray;
  cursor: default;
}
<div id='introductionAds'>
  <ul>
    <li><a href="" target='_blank' class='' id="link1"> Link habilitado </a></li>
    <li><a href="" target='_blank' class='disabled' id="link2"> Link habilitado </a></li>
    <li><a href="" target='_blank' class='disabled' id="link3"> Link habilitado </a></li>
    <li><a href="" target='_blank' class='disabled' id="link4"> Link habilitado </a></li>
    <li><a href="" target='_blank' class='disabled' id="link5" onclick="this.onclick=function(){mostrar('mostrarID');ocultar('introductionAds');}"> Link habilitado </a></li>
  </ul>
  <div>

<div id='mostrarID' style='display:none;'>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
    
asked by anonymous 22.01.2016 / 11:01

3 answers

2

Add a semicolon at the end to call the functions, (it will be called in order)

 <input id="botao" type="button" value="click" onclick="ocultarID(); mostrarID();"/>
    
22.01.2016 / 11:11
1

Dude, if I get it right, you're going to hide one and show the other at the same time. Then you can put everything into one function. It would look like this:

function mostrar (){
  document.getElementById('mostrarID').style.display = 'block';
  document.getElementById('introductionAds').style.display = 'none';
}

And you do not need to pass anything as a parameter, JS looks for the id in the HTML. Try this, if not what you want, just let me know.

    
22.01.2016 / 11:17
0

You can also transcribe this function into one:

function mostrar(id, show){
    var show = (show) ? 'block' : 'none';
    document.getElementById(id).style.display=show;
}

mostrar('introductionAds', true);
mostrar('introductionAds', false);
    
22.01.2016 / 11:22