D
Daz
Hello everyone. I am sure the answer to my question is simple, but I
can't seem to dynamically add an onClick event to my script.
I have a table which is generated dynamically, I am just struggling
getting an onClick event to show in the HTML source.
Any help would be appreciated. Here is a block of my current code which
doesn't work.
var tr1 = document.createElement('tr');
tr1.style.backgroundColor = "blue";
var td1 = document.createElement('td');
var b = document.createElement('b');
var titleSpan = document.createElement('span');
titleSpan.style.color = "white";
table.appendChild(tr1);
tr1.appendChild(td1);
td1.appendChild(b);
b.appendChild(titleSpan);
titleSpan.innerHTML = menuTitle;
titleSpan.onClick = "this.toggle()";
I am assuming that I am missing something with the syntax?
All the best.
Daz.
can't seem to dynamically add an onClick event to my script.
I have a table which is generated dynamically, I am just struggling
getting an onClick event to show in the HTML source.
Any help would be appreciated. Here is a block of my current code which
doesn't work.
var tr1 = document.createElement('tr');
tr1.style.backgroundColor = "blue";
var td1 = document.createElement('td');
var b = document.createElement('b');
var titleSpan = document.createElement('span');
titleSpan.style.color = "white";
table.appendChild(tr1);
tr1.appendChild(td1);
td1.appendChild(b);
b.appendChild(titleSpan);
titleSpan.innerHTML = menuTitle;
titleSpan.onClick = "this.toggle()";
I am assuming that I am missing something with the syntax?
All the best.
Daz.