-1

I followed some StackOverflow questions like this one Getting the text of a <a> tag but I still can't get my text.

for (i = 0; i < 5; i++) { 
var ul = document.getElementById('listExisting');
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href", "#");
a.setAttribute("class", "oneExistingFile");       a.appendChild(document.createTextNode("example"+i))
li.appendChild(a);
ul.appendChild(li);
}

$(document).ready(function() {
  $('.oneExistingFile').click(function() {
    console.log(this.textContent)
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="dropdown-menu" id="listExisting">
</ul>

Here it works but in my code I have undefined despite it's really the same structure enter image description here

What am I doing wrong ?

My listener is like this with Meteor:

  'click .oneExistingFile': function(event, template){
    console.log(this.textContent);
  }
Community
  • 1
  • 1
Jerome
  • 1,162
  • 2
  • 16
  • 32

1 Answers1

1

How about this?

'click .oneExistingFile': function(event, template){
    console.log(event.target.text);
  }
blueren
  • 2,730
  • 4
  • 30
  • 47