Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  41] [ 4]  / answers: 1 / hits: 28551  / 10 Years ago, mon, march 3, 2014, 12:00:00

I'm trying something pretty simple in JS but I can't make it work...



I would like when clicking on a div to add a negative margin-left to another div, but I want it to happened everytime I click on the div, not only one time as it does now.
Eveytime I click on my #next_nav, I would like the #nav to move from 10px negative.
here it only works one time.
here is my js :



$(function() {
$('#next_nav').click(function () {
$( #nav ).css('margin-left','-10px');
});
});


and my HTML :



<div id=next_nav></div>
<div id=nav></div>


here is my JSfiddle : http://jsfiddle.net/Beyzd/



can anybody helps me with this ?
thanks a lot,


More From » jquery

 Answers
8

add an = in front of your value:



$(function() {
$('#next_nav').click(function() {
$('#nav').css('margin-left', '-=10px');
});
});


Working Fiddle



EDIT



If you want to animate it, use animate() method. Here is a fiddle for you.


[#72194] Saturday, March 1, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ernest

Total Points: 332
Total Questions: 92
Total Answers: 98

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;