Another YUI3 question.
I want to add a class(.two) to all table rows with 2 classes and another class(.three) to all table rows with 3 classes.
I found this piece JQuery of code from another question on here, I suspect this will work, but need to convert it to YUI3 and also allow for the two classes to be added, as well as changing the div to somehow:
$(function(){
var div = $('div[class*=" "]').filter(function(){
var clsArray = $.trim(this.className.split(' ');
return clsArray.size > 1;
});
div.css('background','yellow');
});
jsfiddle for above exmaple here:http://jsfiddle.net/udBZy/3/
Thanks!
EDIT:
Here is what I have so far, but no luck :(
$(function() {
YUI().use('node', function(Y) {
var div = Y.all()('div[class*=" "]').filter(function(){
var clsArray = Y.all().Lang.trim(this.className).split(' ');
return clsArray.length > 1;
});
div.setStyle('background','yellow');
});
});
Here is the solution, via the YUI forums. This might help someone in the future:
YUI().use('node', function (Y) {
var re = / {1,}/g;
var div = Y.all('div[class *= " "]').each(function (n) {
var numClasses = Y.Lang.trim(n.get("className")).split(re).length;
n.addClass("numClasses" + numClasses);
n.setContent(n.getContent() + " found " + numClasses);
});
});