How do I add a class to a given element?

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

I have an element that already has a class:

25条回答
  •  -上瘾入骨i
    2020-11-21 12:01

    find your target element "d" however you wish and then:

    d.className += ' additionalClass'; //note the space
    

    you can wrap that in cleverer ways to check pre-existence, and check for space requirements etc..

提交回复
热议问题