Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

handling event changes

<p>This page turns violet when you hold the V key.</p>
<script>
  window.addEventListener("keydown", event => {
    if (event.key == "v") {
      document.body.style.background = "violet";
    }
  });
  window.addEventListener("keyup", event => {
    if (event.key == "v") {
      document.body.style.background = "";
    }
  });
</script>
Comment

handling event changes

<button>Act-once button</button>
<script>
  let button = document.querySelector("button");
  function once() {
    console.log("Done.");
    button.removeEventListener("click", once);
  }
  button.addEventListener("click", once);
</script>
Comment

handling event changes

<button>Click me any way you want</button>
<script>
  let button = document.querySelector("button");
  button.addEventListener("mousedown", event => {
    if (event.button == 0) {
      console.log("Left button");
    } else if (event.button == 1) {
      console.log("Middle button");
    } else if (event.button == 2) {
      console.log("Right button");
    }
  });
</script>
Comment

handling event changes

<a href="https://developer.mozilla.org/">MDN</a>
<script>
  let link = document.querySelector("a");
  link.addEventListener("click", event => {
    console.log("Nope.");
    event.preventDefault();
  });
</script>
Comment

handling event changes

<p>Press Control-Space to continue.</p>
<script>
  window.addEventListener("keydown", event => {
    if (event.key == " " && event.ctrlKey) {
      console.log("Continuing!");
    }
  });
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: facebook game files example 
Javascript :: Javascript Make your console talk! 
Javascript :: apply event listener on id but why not style 
Javascript :: react redux cheat sheet 
Javascript :: chrome extension detect second monitor 
Javascript :: selenium how to automate javascript dialogs 
Javascript :: how to remove &quot in json in "flutter" 
Javascript :: react open on different url instead of localhost 
Javascript :: monk find fields 
Javascript :: scala play json read single field 
Javascript :: variable is not null if used optstring json object 
Javascript :: 11. Which of the following metals catch fire on reaction with air? A. Magnesium B. Manganese C. Potassium D. Calcium 
Javascript :: winwheel js multiline text 
Javascript :: javaascript for unliking twitter 
Javascript :: Updating Object Properties 
Javascript :: .keyinselect 
Javascript :: how to add make touchstart passive in jquery "3.4.0" 
Javascript :: september 
Javascript :: rdlc refresh dataset from object 
Javascript :: create a vue project from scratch with 2.9.6 
Javascript :: sequelize body 
Javascript :: aba translate js 
Javascript :: Ivy J. Livingston 
Javascript :: every character on your keyboard js 
Javascript :: how to sort a 2d array in javascript 
Javascript :: asp.net run javascript on page load 
Javascript :: 1.047222170078745 
Javascript :: threejs torus shape 
Javascript :: react route send informaion in url 
Javascript :: Getting data from one axios to another in componentDidMount 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =