newbie
newbie

Reputation: 1980

external JS file + jquery + css

I have a tr in my html like this

<link rel="stylesheet" type="text/css" href="some_file.css"> // at the head

<c:forEach var="some_variable" items="some_items">
      <tr class="some_class"> some_variable </tr>
</c:forEach>

I also have a submit button

<input type="submit" value="submit" onclick="onSave()"/>

The on click with the button will trigger a function in external javascript

$( '.some_class' ).each( function() {
    if( some condition which involve '.some_class' ) {
       $( this ).addClass('another_class');
    } else {
       $( this ).removeClass('another_class');
    } 
});

The another class is from an external css which have

.another_class {
    background-color: '#ffffb4';
}

I don't get it why the tr doesn't change the background-color when I added a class to the tr, what am I doing wrong?

Upvotes: 0

Views: 101

Answers (1)

gregjer
gregjer

Reputation: 2843

First of all I would correct your input which has unclosed value attribute:

<input type="submit" value="submit onclick="onSave()"/>

change to

<input type="submit" value="submit" onclick="onSave()"/>

you are missing td element in your row

<tr class="some_class"> <td>some_variable</td> </tr>

Ahh and remove apostrophes from your style rule like below:

.another_class {
    background-color: #ffffb4;
}

And basic JSFiddle with your problem -> http://jsfiddle.net/ApfJz/24/

Upvotes: 1

Related Questions