How do I add a class to a given element?

前端 未结 25 2368
清酒与你
清酒与你 2020-11-21 11:34

I have an element that already has a class:

25条回答
  •  粉色の甜心
    2020-11-21 11:55

    Shortest

    image1.parentNode.className+=' box';
    

    image1.parentNode.className+=' box';
    .box { width: 100px; height:100px; background: red; }

提交回复
热议问题