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
Post a Comment