We adding text to paragraph through accessing a javascript object.
<!DOCTYPE html>
<html>
<body>
<h2>Access a JavaScript object</h2>
<p id="demo"></p>
<script>
const myObj = {name:"John", age:30, city:"New York"};
document.getElementById("demo").innerHTML = myObj.name;
</script>
</body>
</html>
We accessing and calling a function that does not return anything.
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Functions</h1>
<p>Accessing a function without () returns the function and not the function result:</p>
<p id="demo"></p>
<script>
function toCelsius(f) {
return (5/9) * (f-32);
}
let value = toCelsius;
document.getElementById("demo").innerHTML = value;
</script>
</body>
</html>
We accessing the first element of array and then add to paragraph element.
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>Bracket Indexing</h2>
<p>JavaScript array elements are accesses using numeric indexes (starting from 0).</p>
<p id="demo"></p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits[0];
</script>
</body>
</html>
When user click the button then a border added to paragraph element.
<!DOCTYPE html>
<html>
<body>
<div id="myDiv">This is a div element.</div>
<br>
<button type="button" onclick="myFunction()">Set border</button>
<script>
function myFunction() {
document.getElementById("myDiv").style.border = "thick solid #0000FF";
}
</script>
</body>
</html>
When user click the button then a class added to element to apply css on it.
<!DOCTYPE html>
<html>
<style>
.myStyle {
background-color: coral;
padding: 16px;
}
</style>
<body>
<h1>The DOMToken Object</h1>
<h2>The add() Method</h2>
<button onclick="myFunction()">Add</button>
<p>Click "Add" to add the "myStyle" class to myDIV.</p>
<div id="myDIV">
<p>I am a myDIV.</p>
</div>
<script>
function myFunction() {
const list = document.getElementById("myDIV").classList;
list.add("myStyle");
}
</script>
</body>
</html>