4
4
* Add class with compatibility for SVG since classList is not supported on
5
5
* SVG elements in IE
6
6
*/
7
- export function addClass ( el : Element , cls : ?string ) {
7
+ export function addClass ( el : HTMLElement , cls : ?string ) {
8
8
/* istanbul ignore if */
9
9
if ( ! cls || ! ( cls = cls . trim ( ) ) ) {
10
10
return
@@ -18,7 +18,7 @@ export function addClass (el: Element, cls: ?string) {
18
18
el . classList . add ( cls )
19
19
}
20
20
} else {
21
- const cur = ' ' + el . getAttribute ( 'class' ) + ' '
21
+ const cur = ` ${ el . getAttribute ( 'class' ) || '' } `
22
22
if ( cur . indexOf ( ' ' + cls + ' ' ) < 0 ) {
23
23
el . setAttribute ( 'class' , ( cur + cls ) . trim ( ) )
24
24
}
@@ -29,7 +29,7 @@ export function addClass (el: Element, cls: ?string) {
29
29
* Remove class with compatibility for SVG since classList is not supported on
30
30
* SVG elements in IE
31
31
*/
32
- export function removeClass ( el : Element , cls : ?string ) {
32
+ export function removeClass ( el : HTMLElement , cls : ?string ) {
33
33
/* istanbul ignore if */
34
34
if ( ! cls || ! ( cls = cls . trim ( ) ) ) {
35
35
return
@@ -43,7 +43,7 @@ export function removeClass (el: Element, cls: ?string) {
43
43
el . classList . remove ( cls )
44
44
}
45
45
} else {
46
- let cur = ' ' + el . getAttribute ( 'class' ) + ' '
46
+ let cur = ` ${ el . getAttribute ( 'class' ) || '' } `
47
47
const tar = ' ' + cls + ' '
48
48
while ( cur . indexOf ( tar ) >= 0 ) {
49
49
cur = cur . replace ( tar , ' ' )
0 commit comments