From 1109132f09d75da9a28b649c7677bb6ce07c40c0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:45 -0500 Subject: initial commit --- .../web/api/globaleventhandlers/onclick/index.html | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 files/es/web/api/globaleventhandlers/onclick/index.html (limited to 'files/es/web/api/globaleventhandlers/onclick/index.html') diff --git a/files/es/web/api/globaleventhandlers/onclick/index.html b/files/es/web/api/globaleventhandlers/onclick/index.html new file mode 100644 index 0000000000..62d6c622ec --- /dev/null +++ b/files/es/web/api/globaleventhandlers/onclick/index.html @@ -0,0 +1,139 @@ +--- +title: GlobalEventHandlers.onclick +slug: Web/API/GlobalEventHandlers/onclick +translation_of: Web/API/GlobalEventHandlers/onclick +--- +
+
{{ ApiRef("HTML DOM") }}
+
+ +
+ +

La propiedad onclick devuelve el manejador del evento click del elemento actual.

+ +
Note: Cuando uses el evento click para ejecutar algo, considera agregar la misma acción al evento keydown, para permitirle el uso a personas que no usan mouse o pantalla táctil.
+ +

Sintaxis

+ +
element.onclick = functionRef;
+
+ +

Donde functionRef es una función - muchas veces el nombre de la función está declarado ya en otro sitio o como una expresión de la función .Ver "JavaScript Guide:Functions" para más detalles.

+ +

el único argumento pasado a la función  manejador de evento especificamente {{domxref("MouseEvent")}} object. Dentro del manejador, this será el elemento sobre él  el evento ha sido invocado.

+ +

Ejemplo

+ +
<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <title>onclick event example</title>
+    <script>
+      function initElement() {
+        var p = document.getElementById("foo");
+        // NOTE: showAlert(); or showAlert(param); will NOT work here.
+        // Must be a reference to a function name, not a function call.
+        p.onclick = showAlert;
+      };
+
+      function showAlert(event) {
+        alert("onclick Event detected!");
+      }
+    </script>
+    <style>
+      #foo {
+        border: solid blue 2px;
+      }
+    </style>
+  </head>
+  <body onload="initElement();">
+    <span id="foo">My Event Element</span>
+    <p>click on the above element.</p>
+  </body>
+</html>
+
+ +

O se puede usar una función anoníma, como esa:

+ +
p.onclick = function(event) { alert("moot!"); };
+
+ +

Notas

+ +

El evento click se genera cuando el usuario hace clic en un elemento. El evento clic ocurrirá después de los eventos mousedown y mouseup.

+ +

Solo se puede asignar un controlador click a un objeto a la vez con esta propiedad. Puede que prefiera utilizar el método {{domxref ("EventTarget.addEventListener()")}} en su lugar, ya que es más flexible y forma parte de la especificación DOM Events.

+ +

Especificación

+ + + + + + + + + + + + + + +
EspecificaciónEstatusComentario
{{SpecName('HTML WHATWG','webappapis.html#handler-onclick','onclick')}}{{Spec2('HTML WHATWG')}}
+ +

Compatibilidad de Navegadores

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Soporte básico{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewChrome for AndroidFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari Mobile
Soporte básico{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
+
-- cgit v1.2.3-54-g00ecf