1

I have a HTML div like,

<div id="tab2" class="tab">
    <div class="alarm" id="alarm">
      <img src="src/alarm.jpg" style="width: 100%; height: 100%; background-size: contain;">
     </div>
 </div>

So I want to open this div when a button click. I tried to add a link to the button like this way,

<a href="#tab2" class="button">Get Start</a>

But this is not working. How can I do this. Please help me !

2
  • 1
    I think you should look at jQuery or something similar. To show the div you need to run javascript to change the CSS visibility of the div. Commented Jun 13, 2018 at 4:45
  • 1
    If you are using bootstrap, you could use collapse: getbootstrap.com/docs/4.0/components/collapse Commented Jun 13, 2018 at 4:47

3 Answers 3

2

HTML Code:

<div id="tab2" class="tab" style="display:none;">
    <div class="alarm" id="alarm">
      <img src="src/alarm.jpg" style="width: 100%; height: 100%; background-size: contain;">
     </div>
 </div>

<a href="#tab2" class="button" onclick="showDiv()">Get Start</a>

Javascript:

function showDiv() {
   document.getElementById('tab2').style.display = "block";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this is the easiest way.
0

Try like this with javascript

<div id="tab2" class="tab" style="display: none;">
  <div class="alarm" id="alarm">
    <img src="src/alarm.jpg" style="width: 100%; height: 100%; background-size: contain;">
  </div>
</div>

<a href="#tab2" class="button" id="button1">Get Start</a>

<script>
  document.getElementById("button1").addEventListener("click", function() {
    document.getElementById("tab2").style.display = "block"
  });
</script>

Comments

-1

Add this css and try :

 #tab2{
   display:none;
  }

 #tab2:target{
   display:block;
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.