Dynamically Added Radio Buttons Onclick Event Not Working?
I am trying following, 1. Get response using Ajax from the users selection which returns me the list of the radio buttons attributes as 2. Once i get the attribute list i am crea
Solution 1:
You can dynamically add en element to the DOM by two ways: by inserting an html code into the parent element or by creating a child element with some properties. In your example the two methods are mixed - therefore senseless.
Method 1. Inserting HTML code:
var radio = '<input type ="radio" id="' + id + '" value="" />';
ele.innerHTML = radio;
document.getElementById(id).onclick = function(){ alert('this is test'); };
Method 2. Creating DOM child:
var radioButton = document.createElement('input');
radioButton.type = "radio";
radioButton.id = id;
radioButton.onclick = function(){ alert('this is test'); };
ele.appendChild(radioButton);
Solution 2:
The property is called onclick
not onClick
Post a Comment for "Dynamically Added Radio Buttons Onclick Event Not Working?"