css - using jQuery to change a background image -


i trying use jquery change background image in table cell, table cell has own class of ".active". using jquery change other elements in same place , work fine think must have wrong in syntax. function using executes after button clicked. my code:

function vehicle(arg){   $(".active").css("color", "blue");     $(".active").css("background-image", "url(../img/car.png)"); }; 

css:

.active{   background-size: 10px 10px;   background-repeat: no-repeat;   border-right: 1px solid none; 

the first line executes fine, have tried following code plus changed picture size in every way can think of :

   $(".active").css("background-image", "../img/car.png");    $(".active").css("background-image", "url('../img/car.png')"); 

can point out did wrong?

you need put .css() relative page. try:

$(".active").css("background-image", "url('img/car.png')"); 

assuming img/ in same directory page, should work. else use relative paths root.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -