I woul like to ask for some help / advise.
I would like to filter all <p>
which contain the button text.
I'm stucked a little bit.
THANK YOU for the support!!
$(document).ready(function() {
$("button").click(function() {
var button = $(this).text().toLowerCase();
$(".color").filter(function() {
$(".color").toggle(jQuery(".color p").text().toLowerCase().indexOf(button) > -1)
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<button>Show All</button>
<button>Green</button>
<button>Red</button>
<button>Blue</button>
</div>
<div class="container">
<div class="color">
<h1>Name</h1>
<p>Red Green</p>
</div>
<div class="color">
<h1>Name</h1>
<p>Green</p>
</div>
<div class="color">
<h1>Name</h1>
<p>Red Blue</p>
</div>
<div class="color">
<h1>Name</h1>
<p>Green Blue</p>
</div>
<div class="color">
<h1>Name</h1>
<p>Blue</p>
</div>
<div class="color">
<h1>Name</h1>
<p>Red </p>
</div>
<div class="color">
<h1>Name</h1>
<p> Green</p>
</div>
</div>