Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
Cómo seleccionar solo al niño si el elemento tiene un parant en el grifo en javascript

Quiero obtener el código del elemento tocándolo en una vista web y enviando el código a mi aplicación. Lo logré, pero cada vez que hago clic en un elemento que tiene un pariente como un div, ambos se seleccionan.

ingrese la descripción de la imagen aquí

**Código Java**

 final WebSettings settings = myWebView.getSettings(); settings.setJavaScriptEnabled(true); myWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); final String injectedJs = "javascript:(function(){" + injectedJs() + "})()"; myWebView.loadUrl(injectedJs); } }); myWebView.addJavascriptInterface( new Object() { @JavascriptInterface public void onClick(String param) { Toast.makeText(MainActivity.this, param, Toast.LENGTH_LONG).show(); } }, "appHost" ); myWebView.loadUrl("file:///android_asset/data.html");

Código JavaScript

 var lastSelectedItem = null; var showHighlighted = function(/* HTML element */view, /*boolean */highlighted) { if (view) { view.style.cssText = highlighted? 'background-color: #ADD8E6; ' :' '; } }; /* This new method, _addEventListener and _eventClick are the same as yours */ Object.prototype.each = function (fn, bind) { for (var i = 0; i < this.length; i++) { if (i in this) { fn.call(bind, this[i], i, this); } } }; var _addListener = document.addEventListener || document.attachEvent, _eventClick = window.addEventListener ? 'click' : 'onclick'; /* I changed the element selection criteria, but you can change it back easily. I am adding event listeners all the leaf elements in the DOM. */ var elements = document.body.getElementsByTagName('*'); elements.each(function (el) { _addListener.call(el, _eventClick, function () { /* First, deal with the previously selected item*/ showHighlighted(lastSelectedItem, false); /* Update the selected item reference */ lastSelectedItem = el; /* Finally, deal with the previously selected item*/ showHighlighted(lastSelectedItem, true); appHost.onClick(el.outerHTML.replace(el.innerHTML , ' ')); }, false); });

Como puede ver en la imagen, hago clic en el botón y el código obtiene tanto el botón como el div. ¿Cómo puedo hacer que solo obtenga el botón, incluso si el botón tiene un pariente?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda