Reputation: 5
On hover I want to change background from a div. therefore I used Jquery. But somehow it doesn't work, not in an empty file, not in an HTML file and not in a file with different Jquery codes.
$('#b').hover(function() {
$('#a').css({
'background': '#ccc'
});
}, function() {
$('#a').css({
'background': 'initial'
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="a">Div A</div>
<div id="b">Div B</div>
Upvotes: 0
Views: 58
Reputation: 669
Your code in working condition please place your jquery code after jquery library
`<!DOCTYPE html>
<head>
</head>
<body>
<div id="a">Div A</div>
<div id="b">Div B</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$('#b').hover(function() {
$('#a').css({
'background': '#ccc'
});
}, function() {
$('#a').css({
'background': 'initial'
});
});
</script>
</body>
</html>`
Upvotes: 2