...

View Full Version : how can we know which element has been clicked



san_crazy
09-07-2008, 02:20 PM
is there any way to know which element(tag) has been clicked?

regards
san

vwphillips
09-07-2008, 04:46 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function Tst(){
var zxcevt=window.event||arguments.callee.caller.arguments[0];
var zxcobj=window.event?zxcevt.srcElement:zxcevt.target;
alert(zxcobj.innerHTML);
}
/*]]>*/
</script></head>

<body>
<div onclick="Tst();" >
<div >Div 1</div>
<div >Div 2</div>
<div >Div 3</div>
<div >Div 4</div>
<div >Div 5</div>
<div >Div 6</div>
</div>
</body>

</html>

san_crazy
10-21-2008, 07:31 AM
hi friends,

i am using this script to change the background color of <input> element at runtime.



<script language="javascript" type="text/javascript">
function changebg(event)
{
event.srcElement.background='#EFFFFB';

}
</script>


and this is being called by


<input onmouseover="changebg('event')" onclick="show_menu_pages('home')" style="position:absolute; left: 8%; top: 5% " title="Home" type="image" name="" value="Home" src="/external/images/home.jpg">


the background color seems not changed.

any suggestion?

rnd me
10-21-2008, 07:00 PM
you were pretty close!

try this cross browser compatible version:


function changebg(e) {
e = e || window.event;
var branch = e.srcElement ? "srcElement" : "target";
e[branch].style.backgroundColor='#EFFFFB';
}



cheers!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum