How to get selected table cell in in Table JavaScript without using jQuery?
With jQuery decision is very simple, but in JavaScript without jQuery – I don’t know how.
I have table:
<table><tr onmouseover="toolnote(this)"><td><td><td></tr></table>
I need to bind “onmouseover” event to every cell in table, but if write this event to every cell it will be very unreadable. It follows that I must bind “onmouseover” to tag through the child and there determine the selected cell. But I do’t lnow how get the child index.
JS Code:
function toolnote(el){
var tt = el.getElementsByTagName('td')
alert(tt[0].innerHTML);
}
In this sample event binding to 0-index.
Anybody help me?
Doubt!
toolnote()as the function name and you are callingtooltip()on the element. Is this a typo?;in the statement.Simple Change:
Or, if you use jQuery, then it is still easier.
You need this in each cell, then:
Make the JavaScript this way:
In case of Firefox:
And this is the reason, I said it will be better to use jQuery, as it handles this cross browser scripting issue, in a better way.
In a Single Line: