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); } });