I do not read the style property of my element when I click, only if I insert the style in the html, if I do it in the css it does not work for me. Thanks
//// MOUSE EVENTS =>
let body = document.getElementsByTagName('body')[0]; //selecciono todo el body para analizar
let resultado = document.getElementsByTagName('p')[1]; //to print result
body.onclick = procesa;
function procesa(e){ // Por que se le pasa un valor???
let ejeX = e.screenX;
let ejeY = e.screenY;
let nodeName = e.target.nodeName; //ver quien desencadeno el evento (e.target daria el objeto)
let objetivo = e.target;
let estilo = objetivo.style.width;
let button = e.button; // left click(0), rigth click(2)=>
let pulsar = '';
switch (button) {
case 0:
pulsar = 'LEFT'
break;
case 2:
pulsar = 'RIGHT'
break;
default:
}
let texto = '-You clicked in the ejeX: ' + ejeX + ' y ejeX: ' + ejeY + '<br>';
texto += '-You clicked in the: ' + nodeName + ' which its object is ' + objetivo + '<br />';
texto += '-You clicked in the: ' + pulsar + ' button with the value of: ' + button + '<br>'
texto += '-The width of the element is: ' + estilo;
resultado.innerHTML = texto;
}
////KEYBOARD EVENTS=>
#section{
height: 100px;
width: 50%;
border: 1px solid black;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>EVENTS</title>
</head>
<body>
<p></p>
<section id="section">
My section
</section>
<aside class="aside">
ASIDE
</aside>
<footer>FOOTER
</footer>
<p id="result"></p>
<script src="app.js" charset="utf-8"></script>
</body>
</html>