<script type="text/javascript">
function B()
{
alert('2');
A();
}
function A()
{
alert('1');
B();
}
</script>
<html>
<body onload="A();">
</body>
</html>
Is it possible to use javascript to do that without jQuery? In my script, A can call B, but B can’t call A? I don’t know why B can’t call A in my script. I’m not sure that is because A hasn’t finished so that B can’t call A right now. A>B>A>B>A>B makes an infinte loop. Can I do the above result in some way?
use setTimeout or setInterval functions. they’r working asynchronously.
in function B javascript will wait for 1 millisecond and call function A, but it will also continue executing your code in B so ‘3’ will be alerted and B will be ended before calling A