This code below is very simple but for some reason it dosent work.
I want a simple function to toggle elements that will active different functions each one. When you click on the first element it changes his class for the second element, when you click on a second element it does other things.
The toggle works well (No JS errors) but I dont know why jQuery do not trigger a click on a class that was added with javascript. I tested too with "addClass" and "removeClass" and got the same result.
I already created a replacement for this (using a if with jquery function "hasclass" to switch behavior when you click on the element). I also understand that I may use other functions with count and all... That would not work for what I wanted but this is not the point...
I just wanted to know why it dosent work because its a common solution that I am sure that I will use again. The code is so simple that I am wondering if I dindt miss something obvious.
Here is fiddle: https://jsfiddle.net/mhbubh8p/17/
HTML:
<div class="toggle aaa">No click so far</div>
Jquery
$(document).ready(function () {
$('.aaa').click(function() {
$('.toggle').toggleClass('aaa zzz');
$('.toggle').html('Class was toggled');
});
$('.zzz').click(function() {
alert("This should work...it dosent... why?");
});
});