Cheatsheet- JavaScript Programming for Web Applications__
Cheatsheet- JavaScript Programming for Web Applications__
Applications
Class or Method Description Example
//Creates the element <p> and text “Hello World”.
Appends Hello World <p> to the HTML document.
<head>
<script>
function addPara() {
An HTML DOM method that after creating var newPara = document.createElement(“p”);
an element, you can use this function to var newText = document.createTextNode(“Hello
appendChild() place the element in the appropriate World!”);
location within the document. The element newPara.appendChild(newText);
document.body.appendChild(newPara);
to append is the only parameter. }
</script>
</head>
<body onload=“addPara()”>
</body>
A property of the Element class that //Removes the CSS style color blue
removes all previously set inline CSS styles <div id="div1" style="color: blue"></div>
<script>
element.removeAttribute() for a particular element. Takes one var div1 =
parameter: the attribute name that is being document.getelementById("div1").getAttribute(“style”);
removed. </script>
An HTML DOM method that, after creating //Creates a new <li> element and places it in the
an element, places a child element in the elementList before the first child of <ul>
let newLI = document.createElement("li");
insertBefore()
appropriate location before an existing newLI.innerText = "new Element";
child. The method takes two parameters, let elementList = document.getElementById("thisList");
the node object to be inserted and the elementList.insertBefore(newLI,
existing node to insert before. elementList.childNodes[0]);
The location object is part of the window //Returns the hostname property
Location Objects object and contains information about the let myhost = location.hostname;
current URL. newLI.innerText = "new Element";
The screen object is part of the window //Returns the height and width of the user’s screen
Screen Objects object class in the DOM that can be used to var height=screen.height;
return properties about the user’s screen. var width=screen.width;
Window Objects The DOM window object is at the top of the //Opens a new browser window with the specified URL
window.open(“http://www.w3schools.com”);
DOM hierarchy and serves as the global
object. Everything in the DOM takes place
in a window. The window object controls
the environment that contains the
document.