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
What am I doing wrong ?
My listener is like this with Meteor:
'click .oneExistingFile': function(event, template){
console.log(this.textContent);
}