Reputation: 3072
This is driving me crazy. I think I have everything right but I am unable to change the color via jQuery. I first was doing this locally then I thought that jQuery can't be used locally, which I learned was incorrect but to make it work I uploaded to my server and it still doesn't work.
What am I doing wrong?
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<script>
$("p").css('color', 'blue');
</script>
<p>Hello</p>
</body>
</html>
Upvotes: 0
Views: 45
Reputation: 103
The above solutions are perfect here is the reason why ? ?
in java script every function is called when event occurs in jquery the first event is on load event when the the code is ready to execute ready event is fired all the functions have to be called with in these ready event only
Upvotes: 0
Reputation: 7332
Wrap it in document.ready
function, Like this,
$(document).ready(function() {
$("p").css('color', 'blue');
});
Upvotes: 0
Reputation: 1890
Try this code .Refer
JS:
$(document).ready(function() {
$("p").css('color', 'blue');
});
Upvotes: 0
Reputation: 6877
Description: Specify a function to execute when the DOM is fully loaded.
$(document).ready(function() {
$("p").css('color', 'blue');
});
Upvotes: 0
Reputation: 17366
You only forgot to wrap your code inside DOM ready handler
$(document).ready(function(){
$("p").css('color', 'blue');
})
Upvotes: 1
Reputation: 38102
Put your code inside
$(document).ready(function() {
$("p").css('color', 'blue');
});
Upvotes: 0