Skip to content Skip to sidebar Skip to footer

Jquery: Using Multiple Arrays To Match Class Attribute Which Determines Childnodes Html?

I have a weekly schedule that I update manually using a static table.
October 212:30 pm

Solution 1:

I would suggest using an object:

var compClass = {
    'al' : 'alpha',
    'be' : 'beta',
    'ga' : 'gamma',
    'de' : 'delta'
}
var k = Object.keys(compClass);

$('tr[class]').each(function() {
    var prop = $.grep(this.className.split(' '), function(value) {
                    return k.indexOf(value) > -1;
               })[0];

    if (prop) this.children[2].innerHTML = compClass[prop];
});

http://jsfiddle.net/3wGmR/1/

Solution 2:

This should do the trick:

$.map($("tr"), function(tr, i) {

        $.each(compClass, function(index, someClass){
            if ($(tr).hasClass(someClass)) {
                classIndex = compClass.indexOf(someClass);
                compVal = competitions[classIndex];
                $(tr).find(".competition").each(function() {this.innerHTML = compVal});
            };
        });
    });
});

http://jsfiddle.net/U7qWB/1/

Post a Comment for "Jquery: Using Multiple Arrays To Match Class Attribute Which Determines Childnodes Html?"

Has A Class, Add Class To Table Cell

Let's say I have the following html: …