I have a dynamic list where class is generated by a PHP loop. I would like to know how to detect the added class as a future className might be added in the near future through CMS. Currently, I am doing it manually and want it to make it automated
for example
<ul id="Portfoliolist">
<li class="2020">Name</li>
<li class="2019">Name</li>
<li class="2018">Name</li>
<li class="2017">Name</li>
<li class="2016">Name</li>
</ul>
jQuery Manual
$('.2020').click(function() {
$('.portfolio_image 2019').css('display','none');
});
$('.2019').click(function() {
$('.portfolio_image 2020').css('display','none');
});
in the near future, a class name might be added like 2021 in the backend and will result to
<ul id="Portfoliolist">
<li class="2021">Name</li> <!-- added through loop -->
<li class="2020">Name</li>
<li class="2018">Name</li>
<li class="2017">Name</li>
<li class="2016">Name</li>
</ul>
and the script will not work of the new class since 2021 doesn't exist in the jQuery code
$('.2019').click(function() {
$('.portfolio_image 2020').css('display','none');
$('.portfolio_image 2019').css('display','block');
});
$('.2020').click(function() {
$('.portfolio_image 2019').css('display','none');
$('.portfolio_image 2020').css('display','block');
});
<div class="portfolio_image 2019"> ...list of portfolio </div>
<div class="portfolio_image 2018"> ...list of portfolio </div>
portfolio_image? Is it the same element hidden by alllielement clicks? Would relevant HTML help?