1// create div element by javascript with class
2
3var div = document.createElement('div');
4div.className = "div1";
5
1Let suppose we are creating a div using javascript create element
2// create a new div element
3 var newDiv = document.createElement("div");
4// assigning class name to the new div
5 newDiv.className = "className";
1class Person {
2 constructor(name, age) {
3 this.name = name;
4 this.age = age;
5 }
6 present = () => { //or present(){
7 console.log(`Hi! i'm ${this.name} and i'm ${this.age} years old`)
8 }
9}
10let me = new Person("tsuy", 15);
11me.present();
12// -> Hi! i'm tsuy and i'm 15 years old.
1class Person {
2 constructor(name, age) {
3 this.name = name;
4 this.age = age;
5 }
6 displayInfo() {
7 return this.name + ' is' + this.age + " years old";
8 }
9}
10
11const Anthony = new Person('Anthony', 32);