how to make div click-able?

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

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

9条回答
  •  轮回少年
    2020-12-08 07:41

    Give it an ID like "something", then:

    var something = document.getElementById('something');
    
    something.style.cursor = 'pointer';
    something.onclick = function() {
        // do something...
    };
    

    Changing the background color (as per your updated question):

    something.onmouseover = function() {
        this.style.backgroundColor = 'red';
    };
    something.onmouseout = function() {
        this.style.backgroundColor = '';
    };
    

提交回复
热议问题