samedi 25 avril 2015

How to use variable in href and pass to click event function to javascript


I have several href links in my jade and each link is generated using a variable passed in by some variables.

The code in jade is like this:

each rows in meters
    li: a#myLink(href= "/meters/" + rows.meterID)= rows.metername

So in my JavaScript part, I added a event listener to each link so that want to generate different pages according to the variables. So that I can add an event listener and emit that variable using socket like this:

  document.getElementById("myLink").addEventListener("click", function(){
     document.getElementById("visualization").innerHTML = "";
     socket.emit('building', window.location.pathname);
  });

Any help would be appreciated!


Aucun commentaire:

Enregistrer un commentaire