Ver Mensaje Individual
  #6 (permalink)  
Antiguo 17/02/2017, 14:46
mpozo
 
Fecha de Ingreso: noviembre-2015
Mensajes: 231
Antigüedad: 8 años, 6 meses
Puntos: 86
Respuesta: Javascript funciona en código pero no en archivo

¿Te funciona esto?
Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html dir="ltr" lang="es-es">
  3.     <head>
  4.         <title></title>
  5.         <meta charset="utf-8">
  6.         <meta name="viewport" content="user-scalable=yes, width=device-width, initial-scale=1">
  7.         <style>
  8.            
  9.         </style>
  10.         <script src="prueba.js"></script>
  11.     </head>
  12.     <body>
  13.  
  14.         <div id="container">
  15.             <div class="header">
  16.                 <div class="logo">Usuario</div>
  17.                 <div class="flex-column">
  18.                     <section id="ocultar">Teléfono y email</section>
  19.                     <section>
  20.                         <ul>
  21.                             <li>Opción 1</li>
  22.                             <li>Opción 2</li>
  23.                         </ul>
  24.                     </section>
  25.                 </div>
  26.             </div>
  27.         </div>
  28.  
  29.     </body>
  30. </html>

prueba.js
Código Javascript:
Ver original
  1. document.addEventListener('DOMContentLoaded', function() {
  2.  
  3.     console.log(document.body.textContent);
  4.  
  5.     if(~document.body.textContent.indexOf('Usuario')){
  6.  
  7.         [].forEach.call(document.querySelectorAll('ul > li'), function(elem) {
  8.  
  9.             elem.style.display = 'none';
  10.         });
  11.     };
  12.  
  13. }, false);