I'm getting started with jQuery. I'v been trying to mix it with some of my preexisting JavaScript code so I don't have to rewrite everything. I have read many places that this is totally doable. However, whenever i include any lines of jQuery the standard JavaScript stops functioning.
Here's a few examples:
<!DOCTYPE html>
<html>
<head>
<style>
#testjquery {
height: 300px;
width: 300px;
}
</style>
</head>
<body>
<div id="testjquery" onclick="testClick()">This is the stuff.</div>
<script src='jquery-1.10.2.min.js'></script>
<script>
$(document).ready(function() {
function testClick() {
document.getElementById("testjquery").style.background = "blue";
}
});
</script>
</body>
</html>
This doesn't work, and when clicks I get a function not defined error.
But, putting this in the body
<body>
<div id="testjquery">This is the stuff.</div>
<script src='jquery-1.10.2.min.js'></script>
<script>
$(document).ready(function() {
$("#testjquery").click(function() {
$(this).css("background", "blue");
});
});
</script>
</body>
Works fine, as does the equivalent in standard JavaScript.