jquery - how to change the background position of an element upon clicking a button -
jquery - how to change the background position of an element upon clicking a button -
ok. know topic has been covered hundred times. , i've tried lastly couple hours. . . , lastly few days. i'm pissed right now. fine, whatever. i'll inquire help.
simple task. click button alter position of object. (i want able click button , scatter list items in list page... sense 1 time figure out how simple task, can figure out there.
i have tried everything, every variation of code saw online. don't know why it's not working me, think must because i'm messing syntax.
<p> want move text </p> <input type = "button" value = "click me"> <script type = "text/javascript" src = "js/jquery.js"></script> <script type = "text/javascript"> $(':button').click(function() { $('p').css({backgroundposition: '100px 0px'}); }); </script>
i tried removing curly braces. tried other variations including:
<script type = "text/javascript"> $(':button').click(function() { $('p').css('backgroundposition', '-100px 0px'); }); </script>
countless hours looking on here , other places solve simple problem.
all want f'ing syntax. can alter background color easily, position has 2 coordinates change, , don't know why none of things i've tried worked.
thanks help in advance.
the bug not in jquery, code correct. problem appears in css properties. consider next variation on code.
$(':button').click(function() { $('p').css({'background-color': 'blue'}); });
here i've changed css update background color vs. position. works fine , demonstrated in next fiddle
fiddle: http://jsfiddle.net/7tuvx/
i apply css straight p
object , see need move proper position, update jquery code accordingly
jquery
Comments
Post a Comment