Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add double click event on a table row using javascript?

var nextRow = tbl.tBodies[0].rows.length;
var row = tbl.tBodies[0].insertRow(nextRow);
row.setAttribute('ondblclick', "return move_to_x_graph();");

This code will add a double click event on a row. But the thing is it's not working in case of Internet Explorer.It's working fine in case of all the other browsers.

For adding style I am handling this:

var cell2 = row.insertCell(1);
var browser = navigator.appName;
if (browser == "Microsoft Internet Explorer") {
    cell2.style.setAttribute("cssText", "color:black; width:300px;");
} else {
    cell2.setAttribute("style", "color:black; width:300px;");
}

Can anybody help me to add double click event using Javascript that will also work in Internet Explorer?

like image 861
Mohit Jain Avatar asked Oct 16 '25 00:10

Mohit Jain


1 Answers

Don't set event handlers using setAttribute, it doesn't work as you'd expect in IE. Instead set it directly on the equivalent event handler property of the element:

row.ondblclick = function() {
    return move_to_x_graph();
};
like image 68
Tim Down Avatar answered Oct 17 '25 13:10

Tim Down



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!