user1611830
user1611830

Reputation: 4867

Setting background-position with jQuery

I have some span tag with let's say #span id that has the property background: url(some image) -22px top no-repeat, which displays some image as a background.

If it has the property background: url(some image) -22px top no-repeat, another image is displayed. The problem is that if I specify ('#span').attr('background-position','0px top') nothing happens, the other image is not displayed. Could someone explain why?

Upvotes: 0

Views: 2803

Answers (1)

Use .css()

$('#span').css('background-position','0px top');

.css() -> Get the value of style properties for the first element in the set of matched elements.

Upvotes: 1

Related Questions