@@ -179,6 +179,22 @@ export function off (el, event, cb) {
179
179
el . removeEventListener ( event , cb )
180
180
}
181
181
182
+ /**
183
+ * For IE9 compat: when both class and :class are present
184
+ * getAttribute('class') returns wrong value...
185
+ *
186
+ * @param {Element } el
187
+ * @return {String }
188
+ */
189
+
190
+ function getClass ( el ) {
191
+ var classname = el . className
192
+ if ( typeof classname === 'object' ) {
193
+ classname = classname . baseVal || ''
194
+ }
195
+ return classname
196
+ }
197
+
182
198
/**
183
199
* In IE9, setAttribute('class') will result in empty class
184
200
* if the element also has the :class attribute; However in
@@ -209,7 +225,7 @@ export function addClass (el, cls) {
209
225
if ( el . classList ) {
210
226
el . classList . add ( cls )
211
227
} else {
212
- var cur = ' ' + ( el . getAttribute ( 'class' ) || '' ) + ' '
228
+ var cur = ' ' + getClass ( el ) + ' '
213
229
if ( cur . indexOf ( ' ' + cls + ' ' ) < 0 ) {
214
230
setClass ( el , ( cur + cls ) . trim ( ) )
215
231
}
@@ -227,7 +243,7 @@ export function removeClass (el, cls) {
227
243
if ( el . classList ) {
228
244
el . classList . remove ( cls )
229
245
} else {
230
- var cur = ' ' + ( el . getAttribute ( 'class' ) || '' ) + ' '
246
+ var cur = ' ' + getClass ( el ) + ' '
231
247
var tar = ' ' + cls + ' '
232
248
while ( cur . indexOf ( tar ) >= 0 ) {
233
249
cur = cur . replace ( tar , ' ' )
0 commit comments