Version 1.7.15

T1A13-Classes-by-Abhay.html

Find a good reference to Javascript Classes
Classes are both Objects that store variables (Called Properties) and Functions that work on the variables (called Methods)

Example Classses code

 class myAnimal {
    constructor(passName, passAge) {
       this.myName = passName;
       this.myAge = passAge;
    }
    myShow(){    
       document.getElementById('myDiv01').innerHTML = 'Hello '+ this.myName + '. You are ' + this.myAge + ' years old
' } myDog = new myAnimal('Snickers', 5) myDog.myShow()

Example working Classes code

Nothing:



...


Click the button to hide all the elements with the class name "ghdj".






What's my favourite color?

Blue



What's my favourite sport?

Volleyball



What's my favourite video game?

GTA





What's my favourite color?
<h2 style="color:yellow;text-shadow:2px 2px blue;font-style:italic;font-size:xx-large;" class="ghdj">Blue</h2>


What's my favourite sport?
<h2 style="color:yellow;text-shadow:2px 2px blue;font-style:italic;font-size:xx-large;" class="ghdj">Volleyball</h2>


What's my favourite video game?
<h2 style="color:yellow;text-shadow:2px 2px blue;font-style:italic;font-size:xx-large;" class="ghdj">GTA</h2>

<script>
function myFunction3() {
  var x = document.getElementsByClassName("ghdj");
  for (var i = 0; i < x.length; i++) {
    x[i].style.display = "none";
  }
}
</script>




  • Using "imp" class to change font decoration of text quickly.

    This is Very Important news.

    Please Pay Attention ...