132
rated 0 times
[
134]
[
2]
/ answers: 1 / hits: 61583
/ 10 Years ago, thu, june 19, 2014, 12:00:00
I am new to Javascript. I want to write a javascript code that when I click a button, the alert window pops up and writes data-message attribute. Here is my code:
<button type=button data-message=a1 onclick=pop()>click</button>
<script>
function pop() {
alert(this.getAttribute(data-message));
}
</script>
but I get the error
TypeError: this.getAttribute is not a function
alert(this.getAttribute(data-message));
I have two questions:
What is wrong?
How can I debug this? How can I find out what
this
refers to? I am using firebug.
Thanks a lot.
More From » javascript