How to get innerHTML of this element in javascript?
问题 Pretty simple question. I have an element (a tag) which has an onclick to call a javascript function. Amoung other things, I want this function to echo the innerHTML of the element that called it. So, in this case, the innerHTML of the atag. How do I do this? 回答1: <element onClick="alert(this.innerHTML);"> ... </element> 回答2: markup: <element id="foo"> ... </element> js: document.getElementById('foo').addEventListener('click', fn); function fn(){ alert(this.innerHTML); } http://jsfiddle.net