Skip to content

Instantly share code, notes, and snippets.

@rambhairao
Last active September 18, 2017 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rambhairao/608c8b58ae4fcaa4f80d0e40b2665f92 to your computer and use it in GitHub Desktop.
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
body{
background-color: blue;}
.one_time{
background-color: red;
}
$(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");
})
});
<!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