@@ -179,6 +179,22 @@ export function off (el, event, cb) {
179179 el . removeEventListener ( event , cb )
180180}
181181
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+
182198/**
183199 * In IE9, setAttribute('class') will result in empty class
184200 * if the element also has the :class attribute; However in
@@ -209,7 +225,7 @@ export function addClass (el, cls) {
209225 if ( el . classList ) {
210226 el . classList . add ( cls )
211227 } else {
212- var cur = ' ' + ( el . getAttribute ( 'class' ) || '' ) + ' '
228+ var cur = ' ' + getClass ( el ) + ' '
213229 if ( cur . indexOf ( ' ' + cls + ' ' ) < 0 ) {
214230 setClass ( el , ( cur + cls ) . trim ( ) )
215231 }
@@ -227,7 +243,7 @@ export function removeClass (el, cls) {
227243 if ( el . classList ) {
228244 el . classList . remove ( cls )
229245 } else {
230- var cur = ' ' + ( el . getAttribute ( 'class' ) || '' ) + ' '
246+ var cur = ' ' + getClass ( el ) + ' '
231247 var tar = ' ' + cls + ' '
232248 while ( cur . indexOf ( tar ) >= 0 ) {
233249 cur = cur . replace ( tar , ' ' )
0 commit comments