0

I want to change the visibility of an element based onclick event of refreshA element

<a id="refreshA">Click here</a>

 <a style="display: none;" id="refreshTab"> Info</a>

here is the js code

<script>
    document.getElementById("refreshA").onclick(function () {
                document.getElementById("refreshTab").style.display = 'block';
                })
</script>
Jack.D
  • 21
  • 1
  • 6
  • 1
    It should be `.onclick = function(){...`, but you better use this: `document.getElementById("refreshA").addEventListener('click', function(){ document.getElementById("refreshTab").style.display = 'block'; });` – blex Aug 16 '16 at 20:05
  • I tried this didn't work :( – Jack.D Aug 16 '16 at 20:13
  • Are you trying to toggle the visibility, or is showing it a one-time thing? – Ted Aug 16 '16 at 20:45
  • I'm trying to show the element – Jack.D Aug 16 '16 at 20:59
  • Possible duplicate of [Changing the style display from none to block in javascript?](http://stackoverflow.com/questions/12174133/changing-the-style-display-from-none-to-block-in-javascript) – Yasel Aug 16 '16 at 21:07
  • Possible duplicate of [Javascript show element on click](http://stackoverflow.com/questions/4357291/javascript-show-element-on-click) – Sainan Aug 16 '16 at 22:59

2 Answers2

0

Try this:

function showhide(){
    document.getElementById("refreshTab").style.display = 'block';
}

document.getElementById('refreshA').onclick=showhide;

See the working fiddle

Ali Adravi
  • 21,707
  • 9
  • 87
  • 85
-1

function myFunction() {
  document.getElementById("refreshTab").style.display = 'block';
}
<a id="refreshA" onclick="myFunction()">Click here</a>
<a style="display: none;" id="refreshTab"> Info</a>
blex
  • 24,941
  • 5
  • 39
  • 72