javascript - this.getAttribute is not a function -
javascript - this.getAttribute is not a function -
i new javascript. want write javascript code when click button, alert window pops , writes data-message attribute. here code:
<button type="button" data-message="a1" onclick="pop()">click</button> <script> function pop() { alert(this.getattribute("data-message")); } </script>
but error
typeerror: this.getattribute not function alert(this.getattribute("data-message"));
i have 2 questions:
what wrong?
how can debug this? how can find out this
refers to? using firebug.
thanks lot.
you need send this
on button like
<button type="button" data-message="a1" onclick="pop(this)">click</button>
and js, capture calling it.
function pop(e) { alert(e.getattribute("data-message")); }
working demo
javascript
Comments
Post a Comment