简体   繁体   中英

I can't access a css style with my javascript code. what is wrong with my code?

<style>
#test{
background-color:#b10515; width=440px;
}
</style>
<script>
...
...
cell[k]=document.createElement('td'); 
var cont = document.createElement('a');
    switch(k){
        case 0:
           cont.innerHTML = jsArray[c].count;
           cell[k].className = 'test';
                break;
    }

Above is my code. In my speculation, cell[k] should have test css style since I set cell[k]

css class as test css. However, test css style was not attached to cell[k] when I run on Tomcat.

can anybody tell me what am I doing wrong with my coding?

#test is an id selector . You are setting a class. Use .test instead.

You also want : not = in your width rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM