javascript - accessing a function inside jquery selector -
i need function public can call inside jquery selector , here code . note : console sayes checkfeat fn not defined .
(function checkfeat() { $(".feat").each(function(){ if (!$(this).hasclass("active")) { $(this).children("p").css("display","none") } else { $(this).children("p").css("display","block") } }); }()); $(".feat h5").on("click",function(){ $(this).parent(".feat").addclass(function(index ,currentclass){ checkfeat(); //console says function not defined why ?!! return "active"; }); });
in javascript file, can write:
function checkfeat() { $(".feat").each(function(){ if (!$(this).hasclass("active")) { $(this).children("p").css("display","none") } else { $(this).children("p").css("display","block") } }); } $(".feat h5").on("click",function(){ $(this).parent(".feat").addclass(function(index ,currentclass){ checkfeat(); //console says function not defined why ?!! return "active"; }); });
then if want separately call function, can call:
checkfeat();
Comments
Post a Comment