-- Nov 16 In-Class Exercise Thread
One issue with this exercise as stated is to get the alert to fire correctly. I think most browsers get hung up on the fact the document isn't fully written when we try to call the alert. The code below though does work:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>In Class Excercise</title>
<meta name="charset" content="utf-8"/>
</head>
<body onload="alert(document.getElementById('foo').innerHTML)">
<div id="foo" style="display:none;">
</div>
<script>
function findTotalResults(obj)
{
document.getElementById("foo").innerHTML =
obj.totalResults;
}
</script>
<script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults">
</script>
</body>
</html>
To get a really awesome solution embed the creation of the onload event handler into findTotalResults.
(
Edited: 2022-11-16)
One issue with this exercise as stated is to get the alert to fire correctly. I think most browsers get hung up on the fact the document isn't fully written when we try to call the alert. The code below though does work:
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>In Class Excercise</title>
<meta name="charset" content="utf-8"/>
</head>
<body onload="alert(document.getElementById('foo').innerHTML)">
<div id="foo" style="display:none;">
</div>
<script>
function findTotalResults(obj)
{
document.getElementById("foo").innerHTML =
obj.totalResults;
}
</script>
<script src="https://www.yioop.com/s/news?f=json&callback=findTotalResults">
</script>
</body>
</html>
To get a really awesome solution embed the creation of the onload event handler into findTotalResults.