JavaScript access CSS class by its name?

后端 未结 6 1871
难免孤独
难免孤独 2021-01-12 16:33

I have to access CSS class by name, and the code below works. However if I try hui[\"myclass\"] or hui[\".myclass\"] instead of hui[0]

6条回答
  •  悲哀的现实
    2021-01-12 16:35

    Yes, Bergi is right:
    You first have to build an index for the style list.
    BUT take care:
    If there is more than 1 stylesheet you first have to loop over the stylesheets. So I like to improve Bergis solution:

    var styleBySelector = {};
    for (var j=0; j

提交回复
热议问题