JavaScript Is there a way to have one hammer event for multiple objects?

I am using the hammer.js touch library to run certain actions on text within an svg file.

A sample can be seen at http://codepen.io/cmgdesignstudios/pen/mebqeW

In my sample, if you tap any letter, it turns blue; the others turn black. The following code executes this action for the first letter.

var Note1 =  document.getElementById('Note1');
var Note1Hammer = new Hammer (Note1);
Note1Hammer.on("tap", function(changecolor){Note1.style.fill="blue";
});

I have 7 different letters. I have 7 similar blocks of code for each letter. Can I use a single hammer variable and hammer on statement for multiple objects so that I don't have to have one for each object?

Answer:1

If you include the jQuery Plugin after the initial call, you can initialize it using jQuery instead.

hammertime = $('.note').hammer()
Answer:2

I need to filter JSON result using jQuery grep.My JSON result look like this: var data = { "items":[ { "Name": "Name 1", "City": "city1" }, { "Name": ...

I need to filter JSON result using jQuery grep.My JSON result look like this: var data = { "items":[ { "Name": "Name 1", "City": "city1" }, { "Name": ...

  1. filtering json object
  2. filtering json object in javascript
  3. filtering json object angularjs
  4. filtering json object angular
  5. filter json object by value
  6. filter json object by key
  7. filter json object by value javascript
  8. filter json object typescript
  9. filter json object python
  10. filter json object in node js
  11. filter json object c#
  12. filter json object array in javascript
  13. filter json object based on key
  14. filter json object array
  15. filter json object by value java
  16. filter json object java
  17. filter json object by property
  18. filter json object array jquery
  19. filter json object js
  20. filter json object jquery

When you want to make a graph in d3 and you read your input from a json file (for example) the code goes pretty much like this : d3.json("data/data.json", function(error, data) { data.forEach(...

When you want to make a graph in d3 and you read your input from a json file (for example) the code goes pretty much like this : d3.json("data/data.json", function(error, data) { data.forEach(...

  1. dynamic json namespace
  2. json dynamic name

I just watched The Definitive Guide to Object-Oriented JavaScript. I will never learn how to do OOP in classical way. It mentioned the new spec (ES6). But as far as I know it is not well supported. Is ...

I just watched The Definitive Guide to Object-Oriented JavaScript. I will never learn how to do OOP in classical way. It mentioned the new spec (ES6). But as far as I know it is not well supported. Is ...

Considering the following code snippet, function outer(data1){ function inner(){ console.log(data1); } return inner; } in the following two function calls, first one works but ...

Considering the following code snippet, function outer(data1){ function inner(){ console.log(data1); } return inner; } in the following two function calls, first one works but ...

  1. closure working javascript
  2. javascript closure not working