xuijs / xui

A tiny javascript framework for mobile web apps.

Home Page:http://xuijs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.addClass() does not Support Multiple Classes

tekmonk opened this issue · comments

If you are adding multiple classes, it works the first time, for example:

x$('div').addClass('myclass1 myclass2 myclassXXX');

But if you run that same line again, the classes are added again. It will keep doing it every time you run said line, so you will have classes added to the element over and over which will look like ... <body class="class1 class2 class1 class2 class1... so on and so forth.

I am an awful programmer, especially with javascript, but this change has worked (not sure how to commit this or whatever?)

addClass: function(className) {
    cname = className.split(' ');
    for( i=0; i<cname.length ; i++){
        return this.each(function(el) {
            if (hasClass(el, cname[i]) === false) {el.className = trim(el.className + ' ' + className);}
        });
    }
},