How to include HTML code snippets in HTML ?
- Create two HTML files “index.html” and “gfg.html“.
- Create another HTML file for including the “index.html” file.
- Call the function in the main ( “index.html“) file to include the snippet of “gfg.html“.
Step 1: Create the main HTML file named “index.html” file. This file will display a heading text ‘This is index.html’.
Step 2: Create another HTML file of your choice for inclusion in the “index.html” file and save this file in the same directory in which “index.html” is present. In this article, create an HTML file named “gfg.html” which displays ” GeeksforGeeks A Computer Science Portal For Geeks “.
Step 3: We are going to include the “gfg.html” snippet in the “index.html” file. Including HTML is done by using a GFG-include-html-snippet attribute.
- Traverse the collection of all HTML elements.
- Search for elements with specific attributes.
- Create an HTTP request with the attribute value as the file name.
- Delete the attribute and call this function again.
- Exit function.
Differentiating included gfg.html snippet in index.html: The red border indicates the output of the main index.html and the blue border indicates the output of included HTML snippet.
Please Login to comment...