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.

jsfiddle updated

edit: can try writing in jquery this:

jsfiddle

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

jsfiddle

an alternative:

if want apply background through class selector (here url gets hardcoded in css), (this in practice swordfish0321 talks about):

jsfiddle


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -