Is there a way to redirect to another page by clicking on a div?

Asked

Viewed 1,355 times

4

I have a div:

<div class="col-lg-4 col-sm-6"> //Essa aqui
       <section class="panel div-border-red">
              <div class="symbol red">
                  <i class="fa fa-eye"></i>
              </div>
              <div class="value">
                  <h1 class="count tkts-total" id="stock_danger"></h1>
                  <p>Falta de estoque</p>
             </div>
       </section>
</div>

I wonder if you have any way to redirect to another page by clicking on the div (Without using Angularjs).

  • 1

    <a href="link"> was made for this.

  • 3

    @Felipepaetzold a tip: Never mark a first-time answer. Always wait, depending on your question, a while. No need to rush to score. When you score in a hurry, you take away the motivation of someone wanting to give another answer. Having multiple views can be an advantage.

2 answers

8


You can easily do this by placing a link before starting the div.

See working here

Thus remaining:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Esta linha acima é somente para importar o `CSS` do Bootstrap -->

<a href="http://google.com"><div class="col-lg-4 col-sm-6"> //Essa aqui
       <section class="panel div-border-red">
              <div class="symbol red">
                  <i class="fa fa-eye"></i>
              </div>
              <div class="value">
                  <h1 class="count tkts-total" id="stock_danger"></h1>
                  <p>Falta de estoque</p>
             </div>
       </section>
</div></a>

Show 1 more comment

1

Define a id for div and use the function click

$('#idDiv').click(function() { 
 document.location = 'http://suaurl.com/';
} );
  • It worked, I’ll accept the answer as soon as the system allows.

  • 5

    I understand that answer answers what was asked, and technically it is correct. But it’s a damn good idea to use JS to do what native HTML is. Unfortunately I see a lot of people using this, which is a worrying indicator in terms of market quality.

  • 1

    In this case, just criticizing my answer doesn’t help the AP, so help him by posting your answer as well. So he will have another option and the others who will read this question.

  • 2

    @Jcsaint does not criticize his reply, it is correct. I criticize the author wanting to do this, which was endorsed by the acceptance. Your answer is correct, for what was asked, as I said before. As for the answer, I’ve already posted it as a comment on the question, and Wendell has already come up with the solution. Although on top of everything your answer use jQuery, which also is not in the question, I don’t think there is anything wrong with it (if it had, the staff would negatively).

  • 1

    The other answer having gained 4 points more than this shows by itself what would be the best way to solve the problem. Giving the solution sought is important, but everyone can go further. Depending on jQuery to do this operation is absurd.

Browser other questions tagged

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