I want to make a code that takes the class of an ID each time it is clicked:
html
<ul>
<li id="alert-class" class="class-1">1</li>
<li id="alert-class" class="class-2">2</li>
<li id="alert-class" class="class-3">3</li>
</ul>
Javascript
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function() {
var $alertando = '';
$j("#alert-class").click(function() {
$alertando = $j(this).attr("class");
alert($alertando);
});
});
</script>
Until it works fine, the alert prints the right information, but only prints the value of the first "li" when I click on it. The other "li" s and their class alerts do not work.
Well, I tried to do it in several different ways, I tried to use "each" but I did not succeed in simplifying my code.
Where I want to use it is much more complex than that, but I found it simpler and simpler to understand, and it works the same way, I imagine.
I am waiting for answers and thank you in advance!