css - Cannot update background image with jQuery -
code:
var imgurl = 'img/star.png'; $("#venueid-"+nid).css('background','url("'+imgurl+'") no-repeat top right');
this beginning of function occurs on click. desired result image (img/star.png
) appears in top-right corner of div. unfortunately, when script occurs, nothing happens.
i have double-checked relative location of image, , when changing background gradient had no troubles code.
your html has id="venueid"
, calling $("#venueid-")
. wraped function ... , don't call function anywhere.
according jsfiddle.
so fixed 2 things in jsfiddle , works ... moved width , height html css.
edit: can try writing in jquery this:
or if want have way, change little bit. maybe use onclick instead of calling javascript in href. , use function expression (foo = function(){}
) instead of function declaration (function foo(){}
). here more on that
an alternative:
if want apply background through class selector (here url gets hardcoded in css), (this in practice swordfish0321 talks about):
Comments
Post a Comment