here my function with setTimout call just immedieatly after the click but i wants it to fire ater 10 sec of click
$('#switchsubjects').click(function(e)
{
i++;
var x=$('#subject-class-switch').html();
if(i<2)
{
$(this).append('<ul id="dcl"><li class="ui-btn-inner ui-li">Class</li><li class="ui-btn-inner ui-li">Subjects</li></ul>');
e.stopPropagation();
setTimeout(rm(),10000);
}
else
{
$('#dcl').remove();
i=0;
}
});
function rm()
{
console.log("working");
$('#dcl').remove();
i=0;
}
Try this:
The
setTimeout()function expects the first parameter to be a function reference (or a string, but a string is almost always the wrong choice). By sayingrm()you were actually calling thermfunction at that point and passing its return value tosetTimeout()(in this case the return value isundefined). If you passrmwithout the parentheses that passes a reference to your function thatsetTimeoutcan then call after the delay you specify.The doco at MDN is pretty good for more information and other examples.