Forum Moderators: open

Message Too Old, No Replies

Need help

         

orion_rus

8:01 pm on Oct 10, 2004 (gmt 0)

10+ Year Member



if i have a static construction like this
<div onmouseclick="...">
<div>
....
</div>
</div>
how i can create it dinamically?

Bernard Marx

10:03 pm on Oct 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



var D = document, div1, div2;
div1 = D.createElement('<div>');
div2 = D.createElement('<div>');
div1.onclick = function(){ doSomething() };
div1.appendChild(div2);
D.body.appendChild(div1);

orion_rus

11:47 am on Oct 11, 2004 (gmt 0)

10+ Year Member



Yes u right, but div2, will have onclick too, but i need to know how i can have onclick only on div1?
Thank you very much

Bernard Marx

3:36 pm on Oct 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<head>
<style type="text/css">
#div1 {
width:300px;height:200px;
background-color : yellow; padding:15px;
position:absolute; left:50px;top:50px;
}
#div2 {
background-color : green;
width:150px;height:100px;
position:absolute; left:50px;top:50px;
}

</style>
<script language="JavaScript" type="text/javascript">
// Moz can return textNodes for target.
// Need to test and return parentNode (element).
getEventSrcElement = window.Event
? function(e){var targ=e.target;return targ.nodeType==1?targ:targ.parentNode}
: function() {return event.srcElement}

window.onload = function()
{
var D = document, div1, div2;
div1 = D.createElement('<div>');
div1.id = 'div1';
div2 = D.createElement('<div>');
div2.id = 'div2';
div1.onclick = doSomething;
div1.appendChild(div2);
D.body.appendChild(div1);
}

function doSomething(eMoz)
{
var src = getEventSrcElement(eMoz);
if(src!=this) return;
alert(this.id)
}

</script>
</head>
<body>

Bernard Marx

3:39 pm on Oct 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



..is one way. Maybe not the best available.

orion_rus

6:29 pm on Oct 11, 2004 (gmt 0)

10+ Year Member



ohh.. i try this, but it doesn't help me,
now i tried it with table and it doesn't work, may be another way?