If hasClass condition not working jquery -


i trying find out how show/hide element depending on fact whether element ".question a" has class "checked" or not. isn't working. knows why ;( ?

$().ready(function() {      var mylink = ".question a";     if (mylink.hasclass('checked')) {          $('.answer').show(300);     }     else {         $('.answer').hide(300);     }     }); 

try like

$(document).ready(function() {     var mylink = $(".question a");     if (mylink.hasclass('checked')) { //you can use $(this).hasclass         $('.answer').show(300);     }     else {         $('.answer').hide(300);     }    }); 

if want change status of link call same while event triggered like

$(mylink).on('click',function(){     if ($(this).hasclass('checked')) {          $('.answer').show(300);     }     else {         $('.answer').hide(300);     } }); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo