Change text of a child element using JavaScript - Javascript DOM

Javascript examples for DOM:Element textContent

Description

Change text of a child element using JavaScript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// w w w.  j  a  v a  2s .  c om
document.querySelector('label[for="my"]').textContent = 'Black';
    }

      </script> 
   </head> 
   <body> 
      <li> 
         <input type="radio" id="my" class="radio product-custom-option" name="options[82]"> 
         <span class="label"> 
            <label for="my">None</label> 
         </span> 
      </li>  
   </body>
</html>

Related Tutorials