Reputation: 179
Does anyone have any idea why the code below is not working?
<!DOCTYPE html>
<head>
<title> The wonderfulness of JS and jQuery </title>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.min.js">
<script type="text/javascript">
function writeIt() {
document.write("jQuery version " + $().jquery + " loaded.");
}
</script>
</head>
<body onload="writeIt()">
Hello
</body>
</html>
It is not displaying the jQuery version. I just came across that piece of code when trying to learn some jQuery and JavaScript and wondering why it is not working for me.
Thanks!
Upvotes: 1
Views: 54
Reputation: 38502
This answer is based on your comment part,
<!DOCTYPE html>
<head>
<title> The wonderfulness of JS and jQuery </title>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function writeIt() {
alert("jQuery version " + $().jquery + " loaded.");
/*document.getElementById("maincontent").innerHTML='Body Content';*/
$('#maincontent').append('appended content');
/*document.write("jQuery version " + $().jquery + " loaded.");*/
/*if (typeof jQuery != 'undefined') {
alert(jQuery.fn.jquery);
}
}*/
}
</script>
</head>
<body id="maincontent" onload="writeIt()">
initial content
</body>
</html>
Upvotes: 0
Reputation: 3848
It's just because you didn't end the script
tag...
<script src="http://code.jquery.com/jquery-latest.min.js"> </script>
For the script
tag it's absolutely required. It needs to be fully qualified, it doesn't end with />
.
Upvotes: 4