Last active
September 18, 2017 08:22
-
-
Save rambhairao/608c8b58ae4fcaa4f80d0e40b2665f92 to your computer and use it in GitHub Desktop.
JS Binsimple example of updating variable value with clicks on something// source http://jsbin.com/jawekum
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
body{ | |
background-color: blue;} | |
.one_time{ | |
background-color: red; | |
} |
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
$(document).ready(function(){ | |
$("ul li").eq(0).addClass("one_time"); | |
var target_value = ""; | |
$("ul li").on('click', function(){ | |
var target_var = $("ul li ").index(this); | |
if($("ul li").eq(0).hasClass("one_time")){ | |
target_value = 0 ; | |
} else { | |
target_value = $("ul").children(".one_time").index(); | |
} | |
console.log(target_value); | |
console.log(target_var); | |
$("ul li").eq(target_var).addClass("one_time").siblings().removeClass("one_time"); | |
}) | |
}); |
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 name="description" content="simple example of updating variable value with clicks on something"> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<script src="https://code.jquery.com/jquery-3.1.0.js"></script> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
body{ | |
background-color: blue;} | |
.one_time{ | |
background-color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<ul> | |
<li>one time slide </li> | |
<li>one time slide </li> | |
<li>one time sldie </li> | |
<li>one time slide </li> | |
</ul> | |
<script id="jsbin-javascript"> | |
$(document).ready(function(){ | |
$("ul li").eq(0).addClass("one_time"); | |
var target_value = ""; | |
$("ul li").on('click', function(){ | |
var target_var = $("ul li ").index(this); | |
if($("ul li").eq(0).hasClass("one_time")){ | |
target_value = 0 ; | |
} else { | |
target_value = $("ul").children(".one_time").index(); | |
} | |
console.log(target_value); | |
console.log(target_var); | |
$("ul li").eq(target_var).addClass("one_time").siblings().removeClass("one_time"); | |
}) | |
}); | |
</script> | |
<script id="jsbin-source-css" type="text/css">body{ | |
background-color: blue;} | |
.one_time{ | |
background-color: red; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">$(document).ready(function(){ | |
$("ul li").eq(0).addClass("one_time"); | |
var target_value = ""; | |
$("ul li").on('click', function(){ | |
var target_var = $("ul li ").index(this); | |
if($("ul li").eq(0).hasClass("one_time")){ | |
target_value = 0 ; | |
} else { | |
target_value = $("ul").children(".one_time").index(); | |
} | |
console.log(target_value); | |
console.log(target_var); | |
$("ul li").eq(target_var).addClass("one_time").siblings().removeClass("one_time"); | |
}) | |
}); | |
</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment