javascript - how convert classes of element to an array? -


i have <div> this.

<div id="div" class="a b _c d _e f"></div> 

how can convert classes of <div> javascript array?

var cls = $('#div').attr('class'); cls = $(cls).match(/_\s+/g).join(" "); //separate classes begin underscore. cls = $(cls).toarray(); 

but doesn't work.

use split() function:

var array; array = $('#div').attr('class').split(' '); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -