Javascript change Div style

后端 未结 7 1705
轻奢々
轻奢々 2021-01-03 18:30

I want that part 1 onclick div style changes and part 2 again on click it comes back to normal. I tried doing so but I failed to achieve the

相关标签:
7条回答
  • 2021-01-03 19:05

    A simple switch statement should do the trick:

    function abc() {
        var elem=document.getElementById('test'),color;
        switch(elem.style.color) {
            case('red'):
                color='black';
                break;
            case('black'):
            default:
                color='red';
        }
        elem.style.color=color;
    }
    
    0 讨论(0)
提交回复
热议问题