0

My Code:

<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12 indexpointer">
    <div class="img-txt-box3">
        <h2 class="box-text3">
            <a href="@Url.Action("Compare","Home")">
            Just<br>

            Compare
            </a>
        </h2>
    </div>
</div>

CSS:

.indexpointer {
    cursor:pointer;
}

My Question is: When I click on link pages I can open that following link, but as I have kept my div clickable, I want pages to be opened on click of div. So how can I achieve this?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Shashank
  • 31
  • 9
  • Fiddle would be nice, hard to tell what you want to achieve. – Kristine Jul 17 '15 at 06:18
  • Hope this helps you http://stackoverflow.com/questions/796087/make-a-div-into-a-link – wanderer Jul 17 '15 at 06:19
  • Ok i Have a div in which u can say in center der is a link < a href="Something"> if i click on this link i can go to that following page ...but i have kept now entire div clickable and i want if my users clicks on div then the above href should be triggered how to achieve this – Shashank Jul 17 '15 at 06:20
  • You add a "handler" by using javascript. That acts on the click event raised when the div is clicked. inside the handler (a function) you can do whatever you like. For example redirect to another page. – arkascha Jul 17 '15 at 06:22

3 Answers3

0

Try this :

$(".indexpointer").click(function(){
      window.location= $(this).find("a").attr("href");
})
Muhammad Atif
  • 1,050
  • 1
  • 9
  • 21
0

Try this..

<div onclick="location.href='url'">yadda yadda yadda</div>

jQuery:

$("div").click(function(){
    window.location=$(this).find("a").attr("href"); return false;
});

Make sure to use cursor:pointer for these DIVs

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
wanderer
  • 111
  • 2
0

Simple Solution:

<a href="http://yoursite.com">
  <div>
     Your content....
  </div>
</a>

Using Jquery:

$(".indexpointer").click(function() {
  window.location = $(this).find("a").attr("href"); 
  return false;
});
Mike Phils
  • 3,475
  • 5
  • 24
  • 45