Inserting events on cells generated by insertCell

M

manolopm

Hi:

I've a problem with cells generated by insertCell, I need to add
"onclick" event something like this

html+='\t<td class='+ClassSelection+' id='+i+'-'+j
+' onclick='+this.GetName()+'.Select('+i+','+j+');'
+ this.GetName()+'.Draw(true);>'
+actual.Text+'</td>\n';*/

to generate something like:

<td class="class" id=1-3 onclick=main.Select(1-3);main.Draw(true);>
sometext </td>

with DOM I'm doing something like

var cell=row.insertCell(-1);
cell.innerHTML=actual.Text;
cell.className=ClassSelection;
cell.id=i+'-'+j;

and that works but I don't know how to do to generate the "onclick"
part.... Any help?
 
M

manolopm

and that works but I don't know how to do to generate the "onclick"
part.... Any help?

Answering my own question:

the trick is use setAttribute to the cell. Ex:
cell.setAttribute('onclick','alert(\'something\')');
 
L

-Lost

manolopm said:
Hi:

I've a problem with cells generated by insertCell, I need to add
"onclick" event something like this

html+='\t<td class='+ClassSelection+' id='+i+'-'+j
+' onclick='+this.GetName()+'.Select('+i+','+j+');'
+ this.GetName()+'.Draw(true);>'
+actual.Text+'</td>\n';*/

to generate something like:

<td class="class" id=1-3 onclick=main.Select(1-3);main.Draw(true);>
sometext </td>

with DOM I'm doing something like

var cell=row.insertCell(-1);
cell.innerHTML=actual.Text;
cell.className=ClassSelection;
cell.id=i+'-'+j;

and that works but I don't know how to do to generate the "onclick"
part.... Any help?

cell.onclick = function() { alert(this); }

-Lost
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top