Access a JavaScript Object
Program Info
Program Code
×

Access a JavaScript Object

We adding text to paragraph through accessing a javascript object.

Footer

×

Access 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>

Footer

Accessing a Function Without Returns
Program Info
Program Code
×

Accessing a Function Without Returns

We accessing and calling a function that does not return anything.

Footer

×

Accessing a Function Without Returns

<!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>

Footer

Accessing The First Element of Array
Program Info
Program Code
×

Accessing The First Element of Array

We accessing the first element of array and then add to paragraph element.

Footer

×

Accessing The First Element of Array

<!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>

Footer

Add a Border to Element
Program Info
Program Code
×

Add a Border to Element

When user click the button then a border added to paragraph element.

Footer

×

Add a Border to 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>

Footer

Add Class to Element
Program Info
Program Code
×

Add Class to Element

When user click the button then a class added to element to apply css on it.

Footer

×

Add Class to Element

<!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>

Footer

Add Two Click Events to Same Button
Program Info
Program Code
×

Add Two Click Events to Same Button

We adding two click events on a button, when user click the button then a alert message opened.

Footer

×

Add Two Click Events to Same Button

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript addEventListener()</h2>

<p>This example uses the addEventListener() method to add two click events to the same button.</p>

<button id="myBtn">Try it</button>

<script>
var x = document.getElementById("myBtn");
x.addEventListener("click", myFunction);
x.addEventListener("click", someOtherFunction);

function myFunction() {
  alert ("Hello World!");
}

function someOtherFunction() {
  alert ("This function was also executed!");
}
</script>

</body>
</html>

Footer


×

Name : Krishna Verma    |    Father's Name : Mr. Satish Kumar    |    Email ID : krishnaverma28081997@gmail.com    |    Religion : Hindu    |    Address : Dayampur, kanker khera, Meerut Cantt (250001), UP    |    Date of Birth : 28 August 1997    |    Marital Status : Non-Married    |    Place of Birth : Dayampur Kanker Khera Meerut Cantt.    |    Gender : Male    |    Age : 28    |    Contact : 9520335394    |    Father's Occupation : Sports man    |    Mother's Name : Smt. Kuntesh Devi    |    Mother's Occupation : Homemaker    |    Number of Brothers : 1    |    Number of Sisters : 1    |    Current Residence : Dayampur kanker khera meerut cantt    |    Family Type : Nuclear Family    |    Family Name : verma    |    Height : 5' 6''    |    Weight : 70 kg    |    Complexion : Fair    |    Body Type : Athletic    |    Hair Color : Black    |    Health Status : Good    |    Any Physical Disability : No    |    Highest Qualification : B.Tech (CSE)    |    Master Skill : PHP Laravel    |    Total Projects : 40 +    |    Total Skills : 25 +    |    Languages Known : Hindi and English    |    Website : krishnaportfolio.in    |    Siblings : 3    |    Nationality : Indian    |    Total Experience : 5 Years    |    LinkedIn : https://www.linkedin.com/in/krishna-verma-840b71356/    |    Total Programs : 10000    |    Total Projects : 40    |    Total Skills : 25    |    Total Experience : 5    |    Total DSA Problems : 165    |    Total Served Companies : 2