[removed] Multiple GetElementByID's in one call

前端 未结 4 859
我在风中等你
我在风中等你 2020-12-20 06:58

Really simple question. I have the following code, and would like to consolidate it down as much as possible. Can\'t get it to work though.. tried using commas etc. Is there

4条回答
  •  时光取名叫无心
    2020-12-20 07:31

    No, but since you're using jQuery anyway, you can use that. This will add the statusBox class to the elements with the IDs statusBox25, statusBox75, and statusBox100:

    $("#statusBox25, #statusBox75, #statusBox100").addClass('statusBox');
    

    Alternatively, if you want to remove all of the existing classes and replace them all with statusBox like your original code as doing, you could use this:

    $("#statusBox25, #statusBox75, #statusBox100").attr('class', 'statusBox');
    

提交回复
热议问题