|
|
How to call the onclick event in dynamic div tag - Javascript
|
Views : 2895
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
Hi...
Use the below code to create div tag dynamically and call the javascript function in onclick event.
<html>
<head>
<style>
.dynamicDiv
{
background-image:url(img1.jpg);height:200;width:320; //set the image path correctly
}
</style>
<script type="text/javascript">
function create_element()
{
var divTag=document.createElement("div");
divTag.id="div0";
divTag.setAttribute("class","dynamicDiv");
divTag.onclick=function(){test();};
document.body.appendChild(divTag);
}
function test()
{
alert("call the javascript function");
}
</script>
</head>
<body onload="create_element()">
</body>
</html>
|
|
By Nirmala, On - 2009-06-05 |
|
|
|