how to make div click-able?

前端 未结 9 1108
春和景丽
春和景丽 2020-12-08 07:15
shanghaimale

For div like above,when mouse on,it should become cursor:poin

相关标签:
9条回答
  • 2020-12-08 07:47

    As you updated your question, here's an obtrustive example:

    window.onload = function()
    {
        var div = document.getElementById("mydiv");
    
        div.style.cursor = 'pointer';
        div.onmouseover = function()
        {
            div.style.background = "#ff00ff";
        };
    }
    
    0 讨论(0)
  • 2020-12-08 07:58

    I suggest to use a CSS class called clickbox and activate it with jQuery:

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

    Now the only thing you have to do is mark your div as clickable and provide a link:

    <div id="logo" class="clickbox"><a href="index.php"></a></div>
    

    Plus a CSS style to change the mouse cursor:

    .clickbox {
        cursor: pointer;
    }
    

    Easy, isn't it?

    0 讨论(0)
  • 2020-12-08 07:59

    If this div is a function I suggest use cursor:pointer in your style like style="cursor:pointer" and can use onclick function.

    like this

    <div onclick="myfunction()" style="cursor:pointer"></div>
    

    but I suggest you use a JS framework like jquery or extjs

    0 讨论(0)
提交回复
热议问题