Liam
Liam

Reputation: 9855

Move background position on click event with jQuery

im trying to move the background position of an element when a certain div is clicked only I cant seem to get it working.

My jquery seems fine from the documentation?

$(this).children('ul li').css('background-position-x','100px');

Heres a jsfiddle demo... http://jsfiddle.net/shqcu/

Upvotes: 1

Views: 2055

Answers (3)

Fatima Zohra
Fatima Zohra

Reputation: 2967

$(this).css('background-image','url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQBFaoYPOnLv_EI4sGOisRrHUGhlHjJp7iY2A4RT1PKXAAPxx3f)');

Upvotes: 0

Anthony
Anthony

Reputation: 599

You can't alter an element's background-position with jQuery alone. You need this plugin http://keith-wood.name/backgroundPos.html

Upvotes: 0

VisioN
VisioN

Reputation: 145458

Use find() instead of children():

$(this).find("ul li").css("background-position-x", "100px");

DEMO: http://jsfiddle.net/shqcu/1/

Upvotes: 7

Related Questions