Use jQuery to change a CSS value -


If I have a background image that is defined as:

  #header {Width: 100%; Background: url (/Content/images/header.jpg) -0 0 no-repeat; }  

And I want to overwrite after that page load. Should not this code work?

  $ ("#header"). CSS ('background-image', '/ content / image / f / header_ & lt;% = affiliateID% & gt; jpg')  

Edit: As stated, The script needs to be run after loading the script ... and here things get a little complicated where this is an MVC app ... This code sits in the masterpiece but it is given below under the 'Renderpartial' control: [On my.Master]

   

Then there is Log Infestus .ascx control in that show:

   .jpg') Warning (' It ');}   

When the' document .ready 'adds the cover, there is never a fire. My changed background process is rarely It can only be rewritten because it is present in the stylesheet. (What is to be done, has it been removed from there?) [To press it to try You must do this after loading the page and after that:

Pre> $ (document) .ready (function () ($ ("# header"). CSS ('background-image', 'url (/ content / image / f / header_ <% = affiliateID% & Gt; .jpg) ');})


Comments