the keyword 'this' to call a function

hey all i have a tabe with a td tag like this :

<td onclick='content(this)'>some text here</td>

and here i have a javascript that gets the html element (in my case the td) and shows me the text inside

function content(){ alert (this.innerHTML); }
but i just can’t get it to work … what’s wrong with my codes please ?

This should be in the JavaScript section. What you are doing is passing ‘this’ to the function as the element, so you cannot call ‘this’ from inside the function. You call the element passed to the function. For example:

function content(e) {
	alert(e.innerHTML);
}
Sponsor our Newsletter | Privacy Policy | Terms of Service