Hi letstry,
Refer below code.
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<style>
body {
font-family: 'Arimo', sans-serif;
line-height: 1.5;
}
/* ----- Headings ----- */
h1 {
text-align: center;
white-space: nowrap;
}
h2 {
font-size: 1.8em;
}
h1, h2 {
font-family: 'Merriweather', serif;
}
h3 {
font-size: 1.5em;
}
h4 {
display: inline-block;
margin: 1em auto 0.3em;
font-size: 1.2em;
background-color: #C7D3BF;
}
/* ----- Navbar ----- */
nav {
position: fixed;
width: 20em;
height: 100%;
top: 0;
left: 0;
padding: 0.8em 2em;
background-color: #C7D3BF;
box-shadow: -0.5px 0 10px 0 rgb(118, 118, 118);
}
nav ul {
padding: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
height: 15em;
}
nav li {
list-style-type: none;
padding-left: 1.2em;
}
.nav-link {
text-decoration: none;
font-size: 1.1em;
color: rgb(58, 84, 56);
}
.nav-link:hover {
color: black;
border-bottom: 1.5px solid black;
}
/* ----- Main Documentation ----- */
main {
margin: 2em 0 2em 17em;
padding: 0 2em 0 4em;
}
@media (max-width: 850px) {
nav {
position: absolute;
width: 100%;
box-sizing: border-box;
max-height: 22em;
text-align: center;
}
main {
position: relative;
margin: 25em 0 2em 0;
padding: 0 2em 0 2em;
}
}
code {
display: block;
font-size: 1.2em;
white-space: pre;
position: relative;
background-color: #f7f7f7;
padding: 0.5em;
overflow: auto;
}
hr {
border: 1.5px solid #C7D3BF;
margin: 2.8em auto;
}
.tree, .tree ul {
margin: 0;
padding: 0;
list-style: none
}
.tree ul {
margin-left: 1em;
position: relative
}
.tree ul ul {
margin-left: .5em
}
.tree ul:before {
content: "";
display: block;
width: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
border-left: 1px solid
}
.tree li {
margin: 0;
padding: 0 1em;
line-height: 2em;
color: #369;
font-weight: 700;
position: relative
}
.tree ul li:before {
content: "";
display: block;
width: 10px;
height: 0;
border-top: 1px solid;
margin-top: -1px;
position: absolute;
top: 1em;
left: 0
}
.tree ul li:last-child:before {
background: #fff;
height: auto;
top: 1em;
bottom: 0
}
.indicator {
margin-right: 5px;
}
.tree li a {
text-decoration: none;
color: #369;
}
.tree li button, .tree li button:active, .tree li button:focus {
text-decoration: none;
color: #369;
border: none;
background: transparent;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
outline: 0;
}
</style>
<script>
$.fn.extend({
treed: function (o) {
var openedClass = 'glyphicon-minus-sign';
var closedClass = 'glyphicon-plus-sign';
if (typeof o != 'undefined') {
if (typeof o.openedClass != 'undefined') {
openedClass = o.openedClass;
}
if (typeof o.closedClass != 'undefined') {
closedClass = o.closedClass;
}
};
//initialize each of the top levels
var tree = $(this);
tree.addClass("tree");
tree.find('li').has("ul").each(function () {
var branch = $(this); //li with children ul
branch.prepend("<i class='indicator glyphicon " + closedClass + "'></i>");
branch.addClass('branch');
branch.on('click', function (e) {
if (this == e.target) {
var icon = $(this).children('i:first');
icon.toggleClass(openedClass + " " + closedClass);
$(this).children().children().toggle();
}
})
branch.children().children().toggle();
});
//fire event from the dynamically added icon
tree.find('.branch .indicator').each(function () {
$(this).on('click', function () {
$(this).closest('li').click();
});
});
//fire event to open branch if the li contains an anchor instead of text
tree.find('.branch>a').each(function () {
$(this).on('click', function (e) {
$(this).closest('li').click();
e.preventDefault();
});
});
//fire event to open branch if the li contains a button instead of text
tree.find('.branch>button').each(function () {
$(this).on('click', function (e) {
$(this).closest('li').click();
e.preventDefault();
});
});
}
});
//Initialization of treeviews
$('#tree1').treed();
$('#tree2').treed({ openedClass: 'glyphicon-folder-open', closedClass: 'glyphicon-folder-close' });
$('#tree3').treed({ openedClass: 'glyphicon-chevron-right', closedClass: 'glyphicon-chevron-down' });
</script>
</head>
<body>
<form id="form1" runat="server">
<!-- Navbar -->
<nav id="navbar">
<header>
<h1>Documentation</h1>
</header>
<ul>
<li><a class="nav-link" href="#Introduction">Introduction</a></li>
<li><a class="nav-link" href="#Grammar_and_types">Grammar and types</a></li>
<li><a class="nav-link" href="#Control_flow_and_error_handling">Control flow and error handling</a></li>
<li><a class="nav-link" href="#Loops_and_iteration">Loops and iteration</a></li>
<li><a class="nav-link" href="#Functions">Functions</a></li>
<li><a class="nav-link" href="#Reference">Reference</a></li>
</ul>
</nav>
<main id="main-doc">
<!-- 01-Introduction -->
<section class="main-section" id="Introduction">
<header>
<h2>Introduction</h2>
</header>
<div class="container" style="margin-top: 30px;">
<div class="row">
<div class="col-md-4">
<ul id="tree1">
<p class="well" style="height: 135px;">
<strong>Initialization no parameters</strong>
<br />
<code>$('#tree1').treed();</code>
</p>
<li><a href="#">TECH</a>
<ul>
<li>Company Maintenance</li>
<li>Employees
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>
<li>Employee Maint.</li>
</ul>
</li>
<li>Human Resources</li>
</ul>
</li>
<li>XRP
<ul>
<li>Company Maintenance</li>
<li>Employees
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>
<li>Employee Maint.</li>
</ul>
</li>
<li>Human Resources</li>
</ul>
</li>
</ul>
</div>
<div class="col-md-4">
<p class="well" style="height: 135px;">
<strong>Initialization optional parameters</strong>
<br />
<code>$('#tree2').treed({openedClass : 'glyphicon-folder-open', closedClass : 'glyphicon-folder-close'});</code>
</p>
<ul id="tree2">
<li><a href="#">TECH</a>
<ul>
<li>Company Maintenance</li>
<li>Employees
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>
<li>Employee Maint.</li>
</ul>
</li>
<li>Human Resources</li>
</ul>
</li>
<li>XRP
<ul>
<li>Company Maintenance</li>
<li>Employees
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>
<li>Employee Maint.</li>
</ul>
</li>
<li>Human Resources</li>
</ul>
</li>
</ul>
</div>
<div class="col-md-4">
<p class="well" style="height: 135px;">
<strong>Initialization optional parameters</strong>
<br />
<code>$('#tree3').treed({openedClass:'glyphicon-chevron-right', closedClass:'glyphicon-chevron-down'});</code>
</p>
<ul id="tree3">
<li><a href="#">TECH</a>
<ul>
<li>Company Maintenance</li>
<li>Employees
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>
<li>Employee Maint.</li>
</ul>
</li>
<li>Human Resources</li>
</ul>
</li>
<li>XRP
<ul>
<li>Company Maintenance</li>
<li>Employees
<ul>
<li>Reports
<ul>
<li>Report1</li>
<li>Report2</li>
<li>Report3</li>
</ul>
</li>
<li>Employee Maint.</li>
</ul>
</li>
<li>Human Resources</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<h3>What you should already know</h3>
<p>This guide assumes you have the following basic background:</p>
<ul>
<li>A general understanding of the Internet and the World Wide Web (WWW).</li>
<li>Good working knowledge of HyperText Markup Language (HTML).</li>
<li>Some programming experience. If you are new to programming, try one of the tutorials linked on the main page about JavaScript.</li>
</ul>
<h3>What is JavaScript?</h3>
<p>JavaScript is a cross-platform, object-oriented scripting language used to make webpages interactive (e.g., having complex animations, clickable buttons, popup menus, etc.). There are also more advanced server side versions of JavaScript such as Node.js, which allow you to add more functionality to a website than simply downloading files (such as realtime collaboration between multiple computers). Inside a host environment (for example, a web browser), JavaScript can be connected to the objects of its environment to provide programmatic control over them.</p>
<p>JavaScript contains a standard library of objects, such as Array, Date, Math and a core set of language elements such as operators, control structures, and statements. Core JavaScript can be extended for a variety of purposes by supplementing it with additional objects; for example:</p>
<ul>
<li>Client-side JavaScript</> extends the core language by supplying objects to control a browser and its <>Document Object Model</> (DOM). For example, client-side extensions allow an application to place elements on an HTML form and respond to user events such as mouse clicks, form input, and page navigation.</li>
<li>Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on a server. For example, server-side extensions allow an application to communicate with a database, provide continuity of information from one invocation to another of the application, or perform file manipulations on a server.</li>
</ul>
<p>This means that in the browser, JavaScript can change the way the webpage (DOM) looks. And, likewise, Node.js JavaScript on the server can respond to custom requests from code written in the browser.</p>
<h3>JavaScript and Java</h3>
<p>JavaScript and Java are similar in some ways but fundamentally different in some others. The JavaScript language resembles Java but does not have Java's static typing and strong type checking. JavaScript follows most Java expression syntax, naming conventions and basic control-flow constructs which was the reason why it was renamed from LiveScript to JavaScript.</p>
<p>In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a runtime system based on a small number of data types representing numeric, Boolean, and string values. JavaScript has a prototype-based object model instead of the more common class-based object model. The prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual objects. JavaScript also supports functions without any special declarative requirements. Functions can be properties of objects, executing as loosely typed methods.</p>
<p>JavaScript is a very free-form language compared to Java. You do not have to declare all variables, classes, and methods. You do not have to be concerned with whether methods are public, private, or protected, and you do not have to implement interfaces. Variables, parameters, and function return types are not explicitly typed.</p>
<p>Java is a class-based programming language designed for fast execution and type safety. Type safety means, for instance, that you can't cast a Java integer into an object reference or access private memory by corrupting Java bytecodes. Java's class-based model means that programs consist exclusively of classes and their methods. Java's class inheritance and strong typing generally require tightly coupled object hierarchies. These requirements make Java programming more complex than JavaScript programming.</p>
<p>In contrast, JavaScript descends in spirit from a line of smaller, dynamically typed languages such as HyperTalk and dBASE. These scripting languages offer programming tools to a much wider audience because of their easier syntax, specialized built-in functionality, and minimal requirements for object creation.</p>
<h3>Getting started with JavaScript</h3>
<h4>Hello World</h4>
<p>To get started with writing JavaScript, open the Web Console in multi-line mode, and write your first "Hello world" JavaScript code:</p>
<code>(function(){
"use strict";
/* Start of your code */
function greetMe(yourName) {
alert('Hello ' + yourName);
}
greetMe('World');
/* End of your code */
})();
</code>
<p>Press Cmd+Enter or Ctrl+Enter (or click the Run button) to watch it unfold in your browser!</p>
</section>
<hr />
<!-- 02-Grammar and types -->
<section class="main-section" id="Grammar_and_types">
<header>
<h2>Grammar and types</h2>
</header>
<h3>Declarations</h3>
<p>JavaScript has three kinds of variable declarations.</p>
<ul>
var
<li>Declares a variable, optionally initializing it to a value.</li>
let
<li>Declares a block-scoped, local variable, optionally initializing it to a value.</li>
const
<li>Declares a block-scoped, read-only named constant.</li>
</ul>
<h4>Variables</h4>
<p>You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules.</p>
<p>A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($). Subsequent characters can also be digits (0–9).</p>
<p>Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) as well as "a" through "z" (lowercase).</p>
<p>You can use most of ISO 8859-1 or Unicode letters such as å and ü in identifiers. (For more details, see this blog post.) You can also use the Unicode escape sequences as characters in identifiers.</p>
<p>Some examples of legal names are Number_hits, temp99, $credit, and _name.</p>
<h4>Declaring variables</h4>
<p>You can declare a variable in two ways:</p>
<ul>
<li>With the keyword var. For example, var x = 42. This syntax can be used to declare both local and global variables, depending on the execution context.</li>
<li>With the keyword const or let. For example, let y = 13. This syntax can be used to declare a block-scope local variable. (See Variable scope below.)</li>
</ul>
<p>You can also simply assign a value to a variable For example, x = 42. This form creates an undeclared global variable. It also generates a strict JavaScript warning. Undeclared global variables can often lead to unexpected behavior. Thus, it is discouraged to use undeclared global variables.</p>
<h4>Variable scope</h4>
<p>When you declare a variable outside of any function, it is called a global variable, because it is available to any other code in the current document. When you declare a variable within a function, it is called a local variable, because it is available only within that function.</p>
<p>JavaScript before ECMAScript 2015 does not have block statement scope. Rather, a variable declared within a block is local to the function (or global scope) that the block resides within.</p>
<p>For example, the following code will log 5, because the scope of x is the global context (or the function context if the code is part of a function). The scope of x is not limited to the immediate if statement block.</p>
<code>if (true) {
var x = 5;
}
console.log(x); // x is 5
</code>
<p>This behavior changes when using the let declaration (introduced in ECMAScript 2015).</p>
<code>if (true) {
let y = 5;
}
console.log(y); // ReferenceError: y is not defined
</code>
<br>
<h4>Global variables</h4>
<p>Global variables are in fact properties of the global object.</p>
<p>In web pages, the global object is window, so you can set and access global variables using the window.variable syntax.</p>
<p>Consequently, you can access global variables declared in one window or frame from another window or frame by specifying the window or frame name. For example, if a variable called phoneNumber is declared in a document, you can refer to this variable from an iframe as parent.phoneNumber.</p>
<h4>Constants</h4>
<p>You can create a read-only, named constant with the const keyword.</p>
<p>The syntax of a constant identifier is the same as any variable identifier: it must start with a letter, underscore, or dollar sign ($), and can contain alphabetic, numeric, or underscore characters.</p>
<code>const PI = 3.14;</code>
<p>A constant cannot change value through assignment or be re-declared while the script is running. It must be initialized to a value.</p>
<p>The scope rules for constants are the same as those for let block-scope variables. If the const keyword is omitted, the identifier is assumed to represent a variable.</p>
<p>You cannot declare a constant with the same name as a function or variable in the same scope. For example:</p>
<code>// THIS WILL CAUSE AN ERROR
function f() {};
const f = 5;
// THIS WILL CAUSE AN ERROR TOO
function f() {
const g = 5;
var g;
//statements
}
</code>
<p>However, the properties of objects assigned to constants are not protected, so the following statement is executed without problems.</p>
<code>const MY_OBJECT = {'key': 'value'};
MY_OBJECT.key = 'otherValue';
</code>
<p>Also, the contents of an array are not protected, so the following statement is executed without problems.</p>
<code>const MY_ARRAY = ['HTML','CSS'];
MY_ARRAY.push('JAVASCRIPT');
console.log(MY_ARRAY); //logs ['HTML','CSS','JAVASCRIPT'];
</code>
<h3>Data structures and types</h3>
<h4>Data types</h4>
<p>The latest ECMAScript standard defines eight data types:</p>
<ul>
<li>Seven data types that are primitives:
<ol>
<li>Boolean. true and false.</li>
<li>null. A special keyword denoting a null value. (Because JavaScript is case-sensitive, null is not the same as Null, NULL, or any other variant.)</li>
<li>undefined. A top-level property whose value is not defined.</li>
<li>Number. An integer or floating point number. For example: 42 or 3.14159.</li>
<li>BigInt. An integer with arbitrary precision. For example: 9007199254740992n.</li>
<li>String. A sequence of characters that represent a text value. For example: "Howdy"</li>
<li>Symbol (new in ECMAScript 2015). A data type whose instances are unique and immutable.</li>
</ol>
</li>
<li>and Object</li>
</ul>
</section>
<hr>
<!-- 03-Control flow and error handling -->
<section class="main-section" id="Control_flow_and_error_handling">
<header>
<h2>Control flow and error handling</h2>
</header>
<h3>Conditional statements</h3>
<p>A conditional statement is a set of commands that executes if a specified condition is true. JavaScript supports two conditional statements: if...else and switch.</p>
<h4>if...else statement</h4>
<p>Use the if statement to execute a statement if a logical condition is true. Use the optional else clause to execute a statement if the condition is false.</p>
<p>An if statement looks like this:</p>
<code>if (condition) {
statement_1;
} else {
statement_2;
}
</code>
<p>Here, the condition can be any expression that evaluates to true or false. (See Boolean for an explanation of what evaluates to true and false.)</p>
<p>If condition evaluates to true, statement_1 is executed. Otherwise, statement_2 is executed. statement_1 and statement_2 can be any statement, including further nested if statements.</p>
<p>You can also compound the statements using else if to have multiple conditions tested in sequence, as follows:</p>
<code>if (condition_1) {
statement_1;
} else if (condition_2) {
statement_2;
} else if (condition_n) {
statement_n;
} else {
statement_last;
}
</code>
<p>In the case of multiple conditions, only the first logical condition which evaluates to true will be executed. To execute multiple statements, group them within a block statement ({ … }).</p>
</section>
<hr>
<!-- 04-Loops and interation -->
<section class="main-section" id="Loops_and_iteration">
<header>
<h2>Loops and iteration</h2>
</header>
<h3>while statement</h3>
<p>A while statement executes its statements as long as a specified condition evaluates to true. A while statement looks as follows:</p>
<code>while (condition)
statement
</code>
<p>If the condition becomes false, statement within the loop stops executing and control passes to the statement following the loop.</p>
<p>The condition test occurs before statement in the loop is executed. If the condition returns true, statement is executed and the condition is tested again. If the condition returns false, execution stops, and control is passed to the statement following while.</p>
<p>To execute multiple statements, use a block statement ({ ... }) to group those statements.</p>
<h4>Example 1</h4>
<p>The following while loop iterates as long as n is less than 3:</p>
<code>let n = 0;
let x = 0;
while (n < 3) {
n++;
x += n;
}
</code>
<p>With each iteration, the loop increments n and adds that value to x. Therefore, x and n take on the following values:</p>
<ul>
<li>After the first pass: n = 1 and x = 1</li>
<li>After the second pass: n = 2 and x = 3</li>
<li>After the third pass: n = 3 and x = 6</li>
</ul>
<p>After completing the third pass, the condition n < 3 is no longer true, so the loop terminates.</p>
<h4>Example 2</h4>
<p>Avoid infinite loops. Make sure the condition in a loop eventually becomes false—otherwise, the loop will never terminate! The statements in the following while loop execute forever because the condition never becomes false:</p>
<code>// Infinite loops are bad!
while (true) {
console.log('Hello, world!');
}
</code>
</section>
<hr>
<!-- 05-Functions -->
<section class="main-section" id="Functions">
<header>
<h2>Functions</h2>
</header>
<h3>Defining functions</h3>
<h4>Function declarations</h4>
<p>A function definition (also called a function declaration, or function statement) consists of the function keyword, followed by:</p>
<ul>
<li>The name of the function.</li>
<li>A list of parameters to the function, enclosed in parentheses and separated by commas.</li>
<li>The JavaScript statements that define the function, enclosed in curly brackets, {...}.</li>
</ul>
<p>For example, the following code defines a simple function named square:</p>
<code>function square(number) {
return number * number;
}
</code>
<p>The function square takes one parameter, called number. The function consists of one statement that says to return the parameter of the function (that is, number) multiplied by itself. The statement return specifies the value returned by the function:</p>
<code>return number * number;
</code>
<p>Primitive parameters (such as a number) are passed to functions by value; the value is passed to the function, but if the function changes the value of the parameter, this change is not reflected globally or in the calling function.</p>
<p>If you pass an object (i.e. a non-primitive value, such as Array or a user-defined object) as a parameter and the function changes the object's properties, that change is visible outside the function, as shown in the following example:</p>
<code>function myFunc(theObject) {
theObject.make = 'Toyota';
}
var mycar = {make: 'Honda', model: 'Accord', year: 1998};
var x, y;
x = mycar.make; // x gets the value "Honda"
myFunc(mycar);
y = mycar.make; // y gets the value "Toyota"
// (the make property was changed by the function)
</code>
</section>
<hr />
<!-- 06-Reference -->
<section class="main-section" id="Reference">
<header>
<h2>Reference</h2>
</header>
<p>All the documentation on this page is from <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide">MDN</a>.</p>
</section>
</main>
</form>
</body>
</html>