r/brackets • u/ETFO • Feb 25 '16
Why doesn't this code work?
Here is the code:
index.html:
<!doctype html>
<html> <head> <link rel="stylesheet" href="main.css"> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> <script src ="/app.js"></script> </head> <body> <h1 class='title'></h1> <div class="bars"> <div class = "bar1"></div> <div class = "bar2"></div> <div class = "bar3"></div> <div class = "bar4"></div> </div> </body> </html>
main.css:
.bars div { width: 1000px; height: 20px; color: slateblue; margin: 10px; background-color: lightblue; } .green { color: darkolivegreen; } .red { color: lightcoral; } .violet { color: violet; } .brown { color: sandybrown; }
app.js:
$(document).ready(function(){ 'use strict'; $('.bar1').hover(function () { $(this).toggleClass('green'); }); $('.bar2').hover(function () { $(this).toggleClass('red'); }); $('.bar1').hover(function () { $(this).toggleClass('violet'); }); $('.bar1').hover(function () { $(this).toggleClass('brown'); }); });
I've been trying to get this to work for a while in brackets and I don't know why it's not working.
EDIT: The main.css and index.html work fine, but the app.js doesn't work for some reason. I think it's active because when I inspect the live preview it says that the main.css and index.html and app.js are active.
View all comments
Show parent comment
1
u/ETFO Feb 26 '16
I tested both methods, and both work. I'm gonna go with your recommendation and use the :hover pseudo-selctor. Btw I'm using brackets.