-
-
Save dtstanley/5f79a12ac316f8efff2523e08544d7b5 to your computer and use it in GitHub Desktop.
lightbulb toggle jQ created by dtstanley - https://repl.it/lightbulb_toggle_jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
box-sizing: border-box; | |
font-family: sans-serif; | |
} | |
main { | |
max-width: 960px; | |
margin: 0 auto; | |
min-width: 250px; | |
padding: 30px; | |
} | |
.lightbulb { | |
border: 1px solid grey; | |
padding: 10px; | |
width: 25%; | |
float: left; | |
cursor: pointer; | |
} | |
.lightbulb img { | |
width: 100%; | |
} | |
.bulb-on { | |
background-color: yellow; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>lightbulb toggle drill</title> | |
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> | |
<link href="index.css" rel="stylesheet" type="text/css" /> | |
</head> | |
<body> | |
<main> | |
<div> | |
<div class="lightbulb js-lightbulb"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/lightbulb.svg" alt="Kiwi standing on oval"> | |
</div> | |
<div class="lightbulb js-lightbulb"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/lightbulb.svg" alt="Kiwi standing on oval"> | |
</div> | |
<div class="lightbulb js-lightbulb"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/lightbulb.svg" alt="Kiwi standing on oval"> | |
</div> | |
<div class="lightbulb js-lightbulb"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-65/lightbulb.svg" alt="Kiwi standing on oval"> | |
</div> | |
</div> | |
</main> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lightswitch(){ | |
//user clicks element with .js-lightbulb class | |
$(".lightbulb").click(function(event){ | |
event.stopPropagation(); | |
//other element(s) get .bulb-on removed. | |
$(".lightbulb").removeClass('bulb-on'); | |
//current element gets the .bulb-on class applied | |
$(event.currentTarget).addClass("bulb-on"); | |
}); | |
} | |
$(function(){ | |
lightswitch(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment