I can work with that. Here is a demo:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html id="doc">
<head>
<title>Grab ID - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
var theId
function grabID(e){ //modified from script at: http://www.quirksmode.org/js/events_properties.html#target
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
theId=targ.id
alert(theId) //this line may be removed or commented out
}
document.onclick=grabID;
</script>
</head>
<body id="bod">
Hi
</body>
</html>
Notes: So as to not allow a situation where an element will have no id, even the html and body tags must have one as shown in this demo. Since you are really just after the element, you might want to consider using or otherwise modifying the script this was modified from at Quirksmode.
Bookmarks