html - jQuery count the number of class names WITHIN an element -


i'm working on creating custom select menu , 1 of stumbling blocks have hit transition of classes between default select element , new one. 1 method have tried is..

$(document).ready(function() {     $("select").each(function() {         var class = "select";          if ($(this).attr("class").length > 0) {             class = class + " " + $(this).attr("class");         }     }); }); 

as can see, doing measuring amount of characters found rather amount of instances found. it's 1 of easiest things can't seem head around it. have ideas can do?

i point out, doesn't matter class names are, because absolutely name, if have example 1 custom select want float right, write <select class="right"></select> , class=right noted script , moved on new select.

try

$(document).ready(function () {     var classnames = [];     $("select").each(function () {         var classes = (this.classname || '').split(/\s+/);         $.each(classes, function (i, v) {             if ($.inarray(v, classnames) == -1) {                 classnames.push(v)             }         })     });     console.log(classnames) }); 

demo: fiddle


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -