Vue Js Get Element By Id Example
Hi Guys,
Today, I will learn you how to get element by id in vue js?. We will show vue js get element by id example. if you are a using simple jquery and you require to change text or replace content of specific element then you can do it easily. In vue js you can't do it very simple, but you can do it using refs variable.
So, just see bellow example and learn about that.
Example
<!DOCTYPE html>
<html>
<head>
<title>How to get element by id in vue js? - Nicesnippets.com</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<div id="myId" ref="myId">{{ message }}</div>
<button @click="myFunctionClick()">Click Here</button>
</div>
</body>
<script type="text/javascript">
new Vue({
el: '#app',
data: {
message:"Welcome"
},
methods:{
myFunctionClick: function () {
this.$refs.myId.innerText = 'Hello Bro';
}
}
});
</script>
</html>
It Will help you...
- How to Build VUE JS CRUD Using Node js Express and MySQL?
- Vue js File Upload Axios Php Example
- Vue Js Application Check Current Version In Ubuntu
- Vue JS Get Array Length Or Object Length Tutorial
- Vue JS Download File using Axios Example
- Vue JS Declare Global Variable Example
- Vue Js Sweetalert Modal Notification Tutorial
- Vue Js Toggle Switch Button Tutorial