Hi , I am using Charles Harvey's random background image plugin. But i have a problem when i want to add a new function. I search all the web and i cant find an answer. Need some help. I want to do: If load a blue background image then i want to make tables background color blue If load a red background image then i want to make tables background color red So, i try something. I added the green lines to code that can explain what i try to do. (function($) { $.randombg = { defaults: { directory: "images/backgrounds/", howmany: 3 } } $.fn.extend({ randombg:function(config) { var config = $.extend({}, $.randombg.defaults, config); return this.each(function() { var directory = config.directory, howmany = config.howmany; var which = Math.floor(Math.random()*howmany)+1; [COLOR="green"]if (which<16 ) {//1-15.jpg are blue $('div.tableLedger').css({"background-color" : "#00688B"}); }[/COLOR] $(this).css({"background" : "url(" +directory + which + ".jpg)"}); }) } }) })(jQuery); Code (markup): this is the html <tr class="tableLedger"> and also my css is /* I want to change this 2 class*/ .tableLedger{ font-weight: bold; color: #FFFFFF; background-color: #69D2E7; height: 26px; } .tableSubLedger{ font-weight: bold; background-color: #d2f1f1; height: 22px; } Code (markup):
try something like this: $('div.tableLedger').css("background-color", "#00688B"); // or $('div.tableLedger').css("background", "#00688B"); Code (markup):
Not sure about the HTML around your tr, but I don't see why you have the div included. This should work for the whole tr: The following three coding styles work with jQuery: $('.tableLedger').css({'background-color' : '#00688B'}); // or $('.tableLedger').css({backgroundColor: '#00688B'}); // or $('.tableLedger').css('backgroundColor', '#00688B'); Code (markup):
Thanks for reading and answering my friends. I tried both of them but it doesnt work. I tried tons of combination but cant find "where i am wrong" Thanks for your time and effort. I try 3 of them but i doesnt work. I tried tons of combinations but i cant work the jQuery. Background chances but table color dont. I cant found the mistake. Here is my html around table <table cellspacing="1" cellpadding="3" class="tableBorder" align="center"> <tr class="tableLedger"> <td width="4%"> </td> <td width="56%">Forum</td> <td width="6%" align="center">Topics</td> <td width="6%" align="center">Sent By</td> <td width="28%" align="center">Last Post</td> </tr> Code (markup):
Just for testing purposes, change your tr to: <tr class="tableLedger" id="theTD"> and your javascript to: $('#theTD').css('backgroundColor', '#00688B'); Does it work?
I tried , it doesnt work too Thanks for your reply ThePHPMaster. You are so helpfull. I get the answer in another forum and i want to share it for other people. //Thanks to Engin Deniz $(document).ready(function(){ bgImageTotal=44; randomNumber = Math.round(Math.random()*(bgImageTotal-1))+1; imgPath=('images/'+randomNumber+'.jpg'); $('body').css('background-image', ('url("'+imgPath+'")')); if(randomNumber < 23) { $('.tableLedger').css({"background" : "url(mavi.png)"}); } }); Code (markup):