12

am using twitter bootstrap's panel component. i have below code

<div class="panel panel-info">
            <div class="panel-heading">
                <div class="row">
                    <div class="col-xs-6">
                        <i class="fa fa-comments fa-5x"></i>
                    </div>
                    <div class="col-xs-6 text-right">
                        <p class="announcement-text">My queue</p>
                    </div>
                </div>
            </div>
        </div>

how do i make the entire panel as hyperlink. like i should be able to click on any part of the panel and it should navigate to a different page.

Online examples show making the footer as hyperlink, but i thought it would be better if i can make the entire panel a hyperlink.

i don't want to use metro.js.

Thanks.

user1447718
  • 669
  • 1
  • 11
  • 23

3 Answers3

13

Just wrap the whole panel in an anchor tag.

 <a href="link.com">    
  <div class="panel panel-info">
    <div class="panel-heading">
      <div class="row">
        <div class="col-xs-6">
          <i class="fa fa-comments fa-5x"></i>
        </div>
        <div class="col-xs-6 text-right">
          <p class="announcement-text">My queue</p>
        </div>
      </div>
    </div>
  </div>
</a>
Alan Thomas
  • 1,006
  • 2
  • 14
  • 31
2

Using an anchor tag around the element can mess up some layouts due to ancestor selectors in the stylesheet.

Using an anchor tag as the panel itself also may not inherit from the default panel styles.

The simplest solution with javascript is to put an attribute on the panel div, like href or data-href, then a global event listener (delegate).

 $(document).on('click', '.panel[data-href]:not(a)', function(){
     window.location = $(this).attr('data-href');
 });
stephenr85
  • 151
  • 1
  • 4
0

Try

 $('.panel panel-info').click(function(e) {
        e.preventDefault();
        window.location = 'http://stackoverflow.com/';
    });

Or setting panel's id

       <div class="panel panel-info" id="lnkPanel">


        $('#lnkPanel').click(function(e) {
            e.preventDefault();
            window.location = 'http://stackoverflow.com/';
        });

For .NET MVC 3 or 4 :

<script type="text/javascript">
      var lnkDashboard = '@Url.Action("Index", "Dashboard")';
</script>

  $('#lnkPanel').click(function(e) {
            e.preventDefault();
            window.location = lnkDashboard;
        });

DEMO : The page doesn't allow navigate, but you can see a full example

Mate
  • 4,976
  • 2
  • 32
  • 38
  • Hi, thanks for the reply. instead of using http:// address, i want to use >@Html.ActionLink("My queue", "Index", "Dashboard", null, null). anyway i can achieve that? – user1447718 Dec 04 '13 at 03:22
  • @user1447718 Hi, I guess you're using .net mvc 3 or 4. In this case, try with the Update – Mate Dec 04 '13 at 04:56
  • @MaxGrass Re-Added on jsfiddle – Mate Oct 14 '14 at 20:58