Maybe you shouldn't pass arguments to the function, but examine the
event object that comes with the event. Its srcElement/target property
tells you the immediate receiver of the click.
The air code for this is as follows:
function setBackground(e) {
if (!e) e = window.event;
var el = e.target ? e.target : e.srcElement;
el.style.backgroundColor = "blue";
}
where you don't have the need to cancelBubble, in the same run.
Daz schreef:
> vfk799 wrote:
>
>> This question may be as much about css as javascript. Here is my code.
>>
>> <html>
>> <head>
>> <script>
>> function setBackground(id) {
>> window.alert(id);
>> document.getElementById(id).style.backgroundColor= 'blue';
>> event.cancelBubble=true;
>> }
>> </script>
>> <body>
>> <div id='1div'style="padding:200px;background-color:red"
>> onClick="setBackground('1div');">
>> <div id='2div' style="padding:100px;background-color:yellow"
>> onClick="setBackground('2div');"></div>
>> </div>
>> </body>
>> </html>
--
Bas Cost Budde
Holland
www.heuveltop.nl/BasCB/msac_index.html