js add click listener
document.getElementById("myBtn").addEventListener("click", function() {
alert("Hello World!");
});
js add click listener
document.getElementById("myBtn").addEventListener("click", function() {
alert("Hello World!");
});
event listener javascript
const element = document.querySelector(".class__name");
element.addEventListener("click", () => {
console.log("clicked element");
});
javascript click event
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
js eventlistener to add and remove stylings
const form = document.querySelector('form');
const fname = document.getElementById('fname');
const lname = document.getElementById('lname');
const para = document.querySelector('p');
form.onsubmit = function(e) {
if (fname.value === '' || lname.value === '') {
e.preventDefault();
para.textContent = 'You need to fill in both names!';
}
}
event in buejs
<template>
<div>
<button v-on:click="increment">Increment</button>
<button @click="decrement">Decrement</button>
<h4>Counter Count: {{ counter }}</h4>
</div>
</template>
<script>
export default {
name: 'DataEvent',
data: () => ({
counter: 0
}),
methods: {
increment() {
this.counter++
},
decrement() {
this.counter--
}
}
}
</script>
<style scoped>
button {
padding: 5px;
font-size: 20px;
margin: 10px;
}
h4 {
font-size: 18px;
}
</style>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us