stevewy@hotmail.com wrote:
Quote:
If I surround a number of form elements with a <DIVtag and put an
OnClick in the DIV tag, if I click on any of the form elements
(checkboxes and radios, in this instance) inside the DIV, is there a
way of telling which element has been clicked on/checked/unchecked,
short of putting an onclick into each individual element? Is there a
property that can be read that stores what was last Clicked on? Even
just the NAME or ID?
|
The event object associated with the onclick has either a srcElement
(IE) or target (W3C) property that is a reference to the element that
originally fired the onclick event:
<script type="text/javascript">
function foo(e){
var tgt = e.target || e.srcElement;
alert('You clicked on a ' + tgt.nodeName);
}
</script>
<div style="width: 15em; height: 5em; background-color: #def;"
onclick="foo(event);">
<p>Here is a paragraph <span style="color: blue;">And
here is a span <b>bold</b></span></p>
</div>
--
Rob