adsense

Wednesday, January 11, 2017

asp.net MVC Make DIV redirect

 Suppose you have a DIV element on a page, such that when clicked should behave like a normal Hyperlink. This can be easily achieved using jQuery.

HTML

<div class="logo" data-action ="@Url.Action("ActionName", "ControllerName")" style="cursor: pointer;" >                   
  DivText       
</div>
 
JavaScript

<script>
   $(function() {

     $('.logo').click(function () {
                var url = $(this).attr('data-action');

                if (url !== undefined)
                    window.location.href = url;
            });
});

</script>

No comments:

Post a Comment