xuijs / xui

A tiny javascript framework for mobile web apps.
http://xuijs.com
789 stars 106 forks source link

.addClass() does not Support Multiple Classes #59

Closed tekmonk closed 12 years ago

tekmonk commented 12 years ago

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);}
        });
    }
},