I have added the below HTML and JavaScript code in an HTML file and loaded it in a UIWebView
. On tapping the button "Test", no alert is shown. Actually there is no element in the HTML document with id "mydiv". What is wrong with the code ? or can't I use document.getElementById in UIWebView
?
<input type="button" value="Test" onclick="getElement()"/>
function getElement()
{
var mydiv = document.getElementById("mydiv");
if(typeof (mydiv) == 'undefined')
{
alert(typeof (mydiv));
}
mydiv = document.createElement("div");
mydiv.style.width = 100+"px";
mydiv.style.height = 200+"px";
mydiv.id = "mydiv";
document.body.appendChild(mydiv);
}