I have the following table:
<table>
<tr><td><span onClick='toggleFunction();'>ABC</span></td></tr>
<tr><td><span onClick='toggleFunction();'>PQR</span></td></tr>
<tr><td><span onClick='toggleFunction();'>XYZ</span></td></tr>
<tr><td><span onClick='toggleFunction();'>LMN</span></td></tr>
</table>
The HTML is dynamically generated.
function toggleFunction() {
var innerHtml = //code to get inner html of calling element here
console.log(innerHtml);
}
I want to get the inner html of span from which toggleFunction() is invoked through onClick.
For e.g. when the click is on row 1, ABC should get printed on console. But when the click is on row 3, XYZ should be printed.
Is this possible through Javascript or Dojo? I can not use Jquery. However, I would like to know if this is possible using Jquery or not.
Please note that the span element is without any id.
This is not a duplicate of other question as:
1) The accepted solution uses inline javascript just to alert innerHTML. However, for me, I just want a way to gain a Handle, so that I can do far more required processing inside my function.
2) Other answers on the question are using element id, which is not my case.
toggleFunctioninstead ofalert. I found at least 10 duplicates.var innerHtml = event.target.innerHTML;toggleFunctionis in a separate file, console.log(this.innerHTML) inside toggleFunction does not work. If it does, why not provide a JSFiddle of the same if you feel you know the answer.