1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>getAttributes</title>
<script type='text/javascript'>
var isIE = /msie/.test(navigator.userAgent.toLowerCase());//globale car tres utile (d ailleur detection super sipmliste)
function getAttributes(el){
var a = el.attributes,
l = a.length,
r= {},
i = 0,
n;
for(; i < l; i++){
n = a[i].name;
if(!isIE){
r[n] = a[i].value;
}else if(n != 'style' && el[n]){alert(n+'+'+el[n]);
r[n] = el[n];
}
}
return r;
}
</script>
</head>
<body>
<div id="test" border=0>test</div>
<script type='text/javascript'>
alert(getAttributes(document.getElementById('test')).id);
</script>
</html> |