Make a div into a link

后端 未结 27 1703
栀梦
栀梦 2020-11-22 03:15

I have a

block with some fancy visual content that I don\'t want to change. I want to make it a clickable link.

I\'m looking for something l

27条回答
  •  自闭症患者
    2020-11-22 04:03

    Just have the link in the block and enhance it with jquery. It degrades 100% gracefully for anyone without javascript. Doing this with html isn't really the best solution imho. For example:

    
    

    Then use jquery to make the block clickable (via web designer wall):

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

    Then all you have to do is add cursor styles to the div

        #div_link:hover {cursor: pointer;}
    

    For bonus points only apply these styles if javascript is enabled by adding a 'js_enabled' class to the div, or the body, or whatever.

提交回复
热议问题