Timeout executes the code globally so pic isn't defined. You need closure.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function TimerSwitch(pic) {
TimerRunning=true;
var timer = setTimeout(function() { SwitchPic(pic) }, 4000);
}
function SwitchPic(pic) {
pic.src = "pic2.jpg";
}
</script>
</head>
<body>
<img class="switch" src="pic1.jpg" alt="something" onclick="TimerSwitch(this)" />
</body>
</html>
Bookmarks