Created
January 23, 2017 16:47
-
-
Save anonymous/3fdf90ad05b4c7e959ded9417de558db to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/gukojef
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>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> |
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
.active { | |
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
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