Open DIV after clicking a Link Button

Asked

Viewed 18,126 times

8

I would like to know how to create, whether in CSS3, Javascript or Jquery, a button that, when clicking it, is revealed a DIV on it, and opens a new page with target _Blank.

I’ve done a lot of research, found some things, but nothing concrete. Of course, if possible, I would like something that works in all browsers.

--

Updating

What I wish fits Diego’s answer, but one thing I forgot to quote in the question is if it is possible to open the page link without leaving the current window.

  • I don’t know a method to use target without leaving the current window. I think it’s a question for another question.

2 answers

6

Your question is very broad and can be solved in many ways. Always try to post part of the code you’re working on so we can better help you.

I’ll give you some guidelines.

HTML

HTML should be very simple. Something like:

<button>Clique aqui</button>
<div id="divId" class="hidden"></div>

CSS

The CSS should contain the div so that it stays on top of the button. I didn’t put these styles here. Implement it on your own however convenient. I just added the style that hides the div.

.hidden{
  display: none;
}

Jquery

The following code performs the action you seek.

$('button').on('click',function(){
    $('#divId').show(); // aparece o div
    window.open(seulink,'_blank'); // abre nova janela
});

I hope I’ve helped.

6

HTML

<div id="escondido">
    Eu irei aparecer
</div>
<a href="http://google.com" target="_blank" id="Clique">Clique aqui</a>

CSS

#escondido{
    display:none;
}

Jquery

$( "#Clique" ).click(function() {
  $("#escondido").css("display","block");
});

Jsfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.