I found this question but the solution is not working for me: jQuery click event not working after adding class
I have this code:
$('.play_button i').click(function() {
$('.content').css( "background-position-x", "-800px" );
$(this).addClass('first_section');
});
$( '.play_button i.first_section' ).on( "click", function() {
$('.content').css( "background-position-x", "-1500px" );
});
Why doesn't the .on
function work?
HTML Structure:
<div class="content">
<div class="play_button"><i class="fa fa-play-circle-o"></i></div>
</div>
Also I tried to make it work with if
function, but it doesn't work either.
$('.play_button').on("click", "i", function() {
if ( $( '.play_button i' ).hasClass( ".first_section") ) {
$('.content').css( "background-position-x", "-1500px" );}
else {
$('.content').css( "background-position-x", "-800px" );
$(this).addClass('first_section');
}
});