I am new to jQuery and I am trying to write a .click() function in jQuery that is triggered from #buttons id to .hide() and .show() elements in #cards id.
For example, if I click on .blue div it should only show() .blueCard div and hide .redCard and greenCard
<div id="buttons">
<div class="blue">Click Me!</div>
<div class="red">Click Me!</div>
<div class="green">Click Me!</div>
</div>
<div id="cards">
<div class="blueCard blue"></div>
<div class="redCard red"></div>
<div class="greenCard green"></div>
</div>
This code seems a bit off... and not working!
$("#buttons").each(function(){
var buttonColors = $("#buttons").attr("class").val();
var cardColors = $("#cards").attr("class").val();
buttonColors.on("click", function(){
if ($(buttonColors + cardColors).length > 0) {
carColors.show();
} else {}
carColors.hide();
});
});