Hi Mates,
Actually the below code only creates dynamic DIV in IE, but for Firefox it does not create any DIV.
Also it does not create the event onclick to be triggered when clicking on any area inside the DIV.
I want to create dynamic DIV in firefox and IE + I want onclick event when clicking on the DIV as I want to that click to delete the content of the DIV or you can say collapse it.
Please can you advise?
Many thanks!
<html>
<head>
<script type="text/javascript">
function create_div_dynamic(){
dv = document.createElement('div'); // create dynamically div tag
dv.setAttribute('id',"lyr1"); //give id to it
dv.className="top"; // set the style classname
//set the inner styling of the div tag
dv.style.position="absolute";
dv.style.pixelLeft=20;
dv.style.pixelTop=100;
dv.style.pixelWidth=10;
dv.style.pixelHeight=20;
dv.style.backgroundColor="red";
//set the html content inside the div tag
dv.innerHTML='<br> hiiiiiiiiii <br>';
// attach event onmouseclick to the created div tag
dv.attachEvent("onmouseclick",function(){element_event_onmouseclick();});
//finally add the div id to ur form
document.forms[0].appendChild(dv);
}
function element_event_onmouseclick() //its called for onmouseclick
{
alert("Inside function onmouseclick");
}
</script>
</head>
<body>
<form name = form1>
<input type="button" value="Show DIV" onclick = create_div_dynamic()>
</form>
</body>
</html>