Mukesh Rawat
Mukesh Rawat

Reputation: 2097

Checkbox onclick is not working in IE8 but working in IE9

I'm creating dynamic checkbox and attaching onclick event with that. Below is the code:

var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var checkbox = document.createElement("input");
checkbox.type = 'checkbox';
checkbox.onclick = testClick();
cell1.appendChild(checkbox);

function testClick() {
            alert("Hello");
}

The above piece of code is working fine with IE9 but not with IE8. I'm using Jquery 1.7.1.

Any help will be greatly appreciated. Thanks..

Upvotes: 0

Views: 2205

Answers (2)

Rene Pot
Rene Pot

Reputation: 24815

If you are using jQuery, why not use it? That takes care of cross browser issues

$(domElement).click(function(){
    // do your thing here
});

Upvotes: 3

antyrat
antyrat

Reputation: 27765

You need to pass function handler, not function call to onclick attribute:

checkbox.onclick = testClick;

Upvotes: 3

Related Questions