jsdom and jquery modifying css style of dom elements

I have been using jdom and jquery with my node.js server, and have observed the following strange behavior with the following code:

var divs = window.$('div').each(function() {
              //console.log(" -", $(this));
              $(this).css('background-color','green');
              $(this).addClass('sel');
              this.style.backgroundColor = "green";
            });

I tried to add some style (background color to green) to the divs on the html page using every way I could think. All of the above attempts (I also tried them one by one to see if any of them worked independently) produced the same results, equivalent to: <div id="somedivid" style="">

I wonder if this is a bug, since it won't write any style to it (Always empty inside the quotes), yet adds the style attribute when these divs didn't have one before if you check the original document. Adding the class sel which I created manually at the top of the page in a custom css style block DOES work, however, exactly like you would think it should. The issue is that I really want to be able to dynamically change the style of individual objects while using jsdom. Anyone have any ideas if this is a bug or if I have overlooked something?

By the way, this code works in a normal browser running standard jquery as well just as expected, so it seems likely to be the jsdom implementation somehow.

You missed one way to do it ... maybe this one works:

this.setAttribute('style', 'background-color: green;');

or:

this.setAttribute('class', 'sel');

the latter if the 'sel' class have been defined previously.

If it works it may mean 'jsdom' is not serializing current computed style but just parsed style (in the HTML markup). I believe this is the expected behavior.