ometv

<!DOCTYPE html>
<!-- THIS IS A SMAPLE OF USING 'DOM' INSIDE JAVASCRIPT'-->
<html lang="en">
<head>
   <meta charset="UTF-8" />
   <title>WEB222</title>
   <style> 
      body { margin: 0 18%; }
   </style>
   <script>
		function doit(){
		    var addrParas = document.querySelector("#address").querySelectorAll("p"); 
			//var addrParas = document.getElementById("address").getElementsByTagName("p"); 

			// highlight paragraphs inside of the section with "address" div element: 
			for (var i = 0; i < addrParas.length; i++) {   
					addrParas[i].style.backgroundColor = "yellow"; 
			}
		}
		
		function tryit(){
		    var allParas = document.querySelectorAll("p");

			// highlight all paragraphs in the web page
			for (var i = 0; i < allParas.length; i++) {   
					allParas[i].style.backgroundColor = "lightgreen"; 
			}
		}
	</script>
</head>
<body>
   <h1>WEB222 - Accessing elements within an element (node)</h1>

   <p>Mail to: </p> 
   <div id="address"> 
       <p>70 The Pond Road</p> 
       <p>Toronto, ON</p>
   </div>

   <p>
      Highlight paragraphs inside of the section with "address" div element:<br> 
      <input type="button" onclick="doit()" value="Do it">
   </p>
   <hr>
   
   <p>
	  Highlight all paragraphs in the web page:<br>
      <input type="button" onclick="tryit()" value="Try it">
   </p>
   <hr>


   <!-- for view-source and download -->
   <br><p><a href='' download>Download</a></p>
</body>

</html>

3.86
7
Daudi 120 points

                                    &lt;!DOCTYPE html&gt;
&lt;!-- THIS IS A SMAPLE OF USING 'DOM' INSIDE JAVASCRIPT'--&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
   &lt;meta charset=&quot;UTF-8&quot; /&gt;
   &lt;title&gt;WEB222&lt;/title&gt;
   &lt;style&gt; 
      body { margin: 0 18%; }
   &lt;/style&gt;
   &lt;script&gt;
		function doit(){
		    var addrParas = document.querySelector(&quot;#address&quot;).querySelectorAll(&quot;p&quot;); 
			//var addrParas = document.getElementById(&quot;address&quot;).getElementsByTagName(&quot;p&quot;); 

			// highlight paragraphs inside of the section with &quot;address&quot; div element: 
			for (var i = 0; i &lt; addrParas.length; i++) {   
					addrParas[i].style.backgroundColor = &quot;yellow&quot;; 
			}
		}
		
		function tryit(){
		    var allParas = document.querySelectorAll(&quot;p&quot;);

			// highlight all paragraphs in the web page
			for (var i = 0; i &lt; allParas.length; i++) {   
					allParas[i].style.backgroundColor = &quot;lightgreen&quot;; 
			}
		}
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
   &lt;h1&gt;WEB222 - Accessing elements within an element (node)&lt;/h1&gt;

   &lt;p&gt;Mail to: &lt;/p&gt; 
   &lt;div id=&quot;address&quot;&gt; 
       &lt;p&gt;70 The Pond Road&lt;/p&gt; 
       &lt;p&gt;Toronto, ON&lt;/p&gt;
   &lt;/div&gt;

   &lt;p&gt;
      Highlight paragraphs inside of the section with &quot;address&quot; div element:&lt;br&gt; 
      &lt;input type=&quot;button&quot; onclick=&quot;doit()&quot; value=&quot;Do it&quot;&gt;
   &lt;/p&gt;
   &lt;hr&gt;
   
   &lt;p&gt;
	  Highlight all paragraphs in the web page:&lt;br&gt;
      &lt;input type=&quot;button&quot; onclick=&quot;tryit()&quot; value=&quot;Try it&quot;&gt;
   &lt;/p&gt;
   &lt;hr&gt;


   &lt;!-- for view-source and download --&gt;
   &lt;br&gt;&lt;p&gt;&lt;a href='' download&gt;Download&lt;/a&gt;&lt;/p&gt;
&lt;/body&gt;

&lt;/html&gt;
0

3.86 (7 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source