Solved:
Thanks to eveyrone that tryed to help
Added this code and it worked:
$(function() {
$( ".itemContainer" ).click(function() {
$(this).toggleClass( "showtheitem", 800 ),
$(this).prev(".itemContainer").toggleClass("hide"),
$(".itemContainer").not(this).prev(".itemContainer").removeClass("hide"),
$(".itemContainer").not(this).removeClass("showtheitem");
return false;
});});
You can see how it works at http://jsfiddle.net/JKnjz/3/
I want to add a class to a previous item on click and then after I click again the class to be removed. But I also want that class to be removed if I click on every other item and add a class just to previous item....
Will try to explain by code. I have 7 divs
<div class="itemContainer">1</div>
<div class="itemContainer">2</div>
<div class="itemContainer">3</div>
<div class="itemContainer">4</div>
<div class="itemContainer">5</div>
<div class="itemContainer">6</div>
<div class="itemContainer">7</div>
CSS:
.itemContainer {float:left;width:100px;height:100px;background:#000;margin:5px;color:#fff}
.hide {display:none;}
.showtheitem {width:200px;height:200px;}
Javascript:
$(function() {
$( ".itemContainer" ).click(function() {
$(this).toggleClass( "showtheitem", 800 ),
$(this).prev(".itemContainer").toggleClass("hide"),
$(".itemContainer").not(this).removeClass("showtheitem");
return false;
});
});
So for example if I click on div number 2 it adds class "hide" to div no. 1. If I click on div no. 2 it removes that hide class. That part is ok.
But I have a problem with if click on div no. 2 it add class of "hide" to div no. 1 and if i click for example on div no.6. class "hide" still remains on div. no 1.
I want class "hide" to be removed if I click on every other div.
here you can see how it works jsfiddle.net/JKnjz/1
I hope I gave clear example :)