0

I have this code:

html:

<div class="ui blue button" id="f{{i}}" onclick="Dailer()">Get this!</div>

which returns:

<div class="ui blue button" id="f1" onclick="Dailer()">Get this</div>

And when I use JS:

function Dailer() {
    alert($(this).attr('id'));
}

I get undefined , even when using alert(this.id) doesent work.

But if I run the code on console, it works:

$("#f1").attr("id")
"f1"
Abdelouahab
  • 7,331
  • 11
  • 52
  • 82

1 Answers1

2

All you need to do is to pass this as an argument of the function

<div class="ui blue button" id="f1" onclick="Dailer(this)">Get this</div>

then the definition of your js function would be :

function Dailer(that) {
    alert($(that).attr('id'));
}
Khalid
  • 4,730
  • 5
  • 27
  • 50