This set of code is very large, and I'm hoping if someone could show me a more efficient way of doing this. In particular, the JavaScript code, but HTML and CSS corrections are just as welcome.
$(document).ready(function () {
var item1 = "active";
var item2 = "unactive";
var item3 = "unactive";
var item4 = "unactive";
var item5 = "unactive";
$("#ITEM1").click(function () {
if (item2 = "active") {
$("#item1").fadeIn(1500);
$("#item2").fadeOut(0);
item2 = "unactive";
item1 = "active";
}
if (item3 = "active") {
$("#item1").fadeIn(1500);
$("#item3").fadeOut(00);
item1 = "active";
item3 = "unactive";
}
if (item4 = "active") {
$("#item1").fadeIn(1500);
$("#item4").fadeOut(00);
item1 = "active";
item4 = "unactive";
}
if (item5 = "active") {
$("#item1").fadeIn(1500);
$("item5").fadeOut(00);
}
});
$("#ITEM2").click(function () {
if (item1 = "active") {
$("#item2").fadeIn(1500);
$("#item1").fadeOut(0);
}
if (item3 = "active") {
$("#item2").fadeIn(1500);
$("#item3").fadeOut(0);
}
if (item4 = "active") {
$("#item2").fadeIn(1500);
$("#item4").fadeOut(0);
}
if (item5 = "active") {
$("#item2").fadeIn(1500);
$("#item5").fadeOut(0);
}
});
$("#ITEM3").click(function () {
if (item1 = "active") {
$("#item3").fadeIn(1500);
$("#item1").fadeOut(00);
}
if (item2 = "active") {
$("#item3").fadeIn(1500);
$("#item2").fadeOut(00);
}
if (item4 = "active") {
$("#item3").fadeIn(1500);
$("#item4").fadeOut(00);
}
if (item5 = "active") {
$("#item3").fadeIn(1500);
$("#item5").fadeOut(00);
}
});
$("#ITEM4").click(function () {
if (item1 = "active") {
$("#item4").fadeIn(1500);
$("#item1").fadeOut(00);
}
if (item2 = "active") {
$("#item4").fadeIn(1500);
$("#item2").fadeOut(00);
}
if (item3 = "active") {
$("#item4").fadeIn(1500);
$("#item3").fadeOut(00);
}
if (item5 = "active") {
$("#item4").fadeIn(1500);
$("#item5").fadeOut(00);
}
});
$("#ITEM5").click(function () {
if (item1 = "active") {
$("#item5").fadeIn(1500);
$("#item1").fadeOut(00);
}
if (item2 = "active") {
$("#item5").fadeIn(1500);
$("#item2").fadeOut(0);
}
if (item3 = "active") {
$("#item5").fadeIn(1500);
$("#item3").fadeOut(0);
}
if (item4 = "active") {
$("#item5").fadeIn(1500);
$("#item4").fadeOut(0);
}
});
});
#menuItems {
background-color: #e6e6e6;
}
#itemLayer {
padding-top: 25px;
padding-bottom: 800px;
}
#menuNav h2 {
font-family: 'Arvo';
text-align: center;
}
#menuNav ul {
float: left;
background-color: white;
}
#menuNav li {
padding: 20px;
margin-top: 5px;
font-size: 1.3em;
font-family: 'Lato';
font-weight: 300;
list-style-type: none;
cursor: pointer;
transition: .5s;
}
#menuNav li:hover {
background-color: gray;
color: white;
}
#item2, #item3, #item4, #item5 {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section id="menuItems">
<div id="itemLayer">
<div id="menuNav">
<h2>Menu Items</h2>
<ul>
<li id="ITEM1"><span class="borderText">Item 1</span></li>
<li id="ITEM2"><span class="borderText">Item 2</span></li>
<li id="ITEM3"><span class="borderText">Item 3</span></li>
<li id="ITEM4"><span class="borderText">Item 4</span></li>
<li id="ITEM5"><span class="borderText">Item 5</span></li>
</ul>
</div>
<div id="itemDisplay">
<div class="items" id="item1">
<img src="food-green.jpeg" width="450px" height="250px" alt="item1" />
<h3>Item 1</h3>
<p>Lorem ipsum sit amet</p>
</div>
<div class="items" id="item2">
<img src="food-green.jpeg" width="450px" height="250px" alt="item2" />
<h3>Item 2</h3>
<p>Lorem ipsum sit amet</p>
</div>
<div class="items" id="item3">
<img src="food-green.jpeg" width="450px" height="250px" alt="item3" />
<h3>Item 3</h3>
<p>Lorem ipsum sit amet</p>
</div>
<div class="items" id="item4">
<img src="food-green.jpeg" width="450px" height="250px" alt="item4" />
<h3>Item 4</h3>
<p>Lorem ipsum sit amet</p>
</div>
<div class="items" id="item5">
<img src="food-green.jpeg" width="450px" height="250px" alt="item5" />
<h3>Item 5</h3>
<p>Lorem ipsum sit amet</p>
</div>
</div>
</div>
</section>
=
instead of==
for comparisons? Each of yourif
s will always be executed... \$\endgroup\$