Skip to content

Instantly share code, notes, and snippets.

Created January 23, 2017 16:47
Show Gist options
  • Save anonymous/3fdf90ad05b4c7e959ded9417de558db to your computer and use it in GitHub Desktop.
Save anonymous/3fdf90ad05b4c7e959ded9417de558db to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/gukojef
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.active {
color: red;
}
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.3/vue.js"></script>
<div id="app">
<div v-for="n in 10" @click="logElement($event)">{{ n }}</div>
</div>
<script id="jsbin-javascript">
new Vue({
data: {
elementOnClick: null
},
methods: {
logElement: function(event) {
if(!!this.elementOnClick) {
this.elementOnClick.classList.remove('active');
this.elementOnClick = null;
}
event.target.classList.add('active');
this.elementOnClick = event.target;
},
}
}).$mount('#app');
</script>
<script id="jsbin-source-css" type="text/css">.active {
color: red;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">new Vue({
data: {
elementOnClick: null
},
methods: {
logElement: function(event) {
if(!!this.elementOnClick) {
this.elementOnClick.classList.remove('active');
this.elementOnClick = null;
}
event.target.classList.add('active');
this.elementOnClick = event.target;
},
}
}).$mount('#app');</script></body>
</html>
.active {
color: red;
}
new Vue({
data: {
elementOnClick: null
},
methods: {
logElement: function(event) {
if(!!this.elementOnClick) {
this.elementOnClick.classList.remove('active');
this.elementOnClick = null;
}
event.target.classList.add('active');
this.elementOnClick = event.target;
},
}
}).$mount('#app');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment