I am working on the following example. How I can use the data attribute data-st="" to filter adding class to element as below? For example I am trying to add the .red to ONLY element which have data-st="red"
$("button").click(function(){
$("p").each(function(){
$(this).addClass('red');
});
});
.red{color:red;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Apply</button>
<p class="" data-st="green"> App </p>
<p class="" data-st="red"> App </p>
<p class="" data-st="black"> App </p>
<p class="" data-st="green"> App </p>
<p class="" data-st="red"> App </p>
<p class="" data-st="blue"> App </p>
<p class="" data-st="green"> App </p>