Answers for "event handler javascript"

46

js add click listener

document.getElementById("myBtn").addEventListener("click", function() {
  alert("Hello World!");
});
Posted by: Guest on July-10-2020
33

event listener javascript

const element = document.querySelector(".class__name");

element.addEventListener("click", () => {
	console.log("clicked element");
});
Posted by: Guest on December-31-2019
9

javascript click event

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>
Posted by: Guest on April-10-2020
0

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!';
  }
}
Posted by: Guest on April-08-2020
0

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>
Posted by: Guest on March-14-2021

Code answers related to "event handler javascript"

Browse Popular Code Answers by Language