Web Development Articles - Page 506 of 1049

Returning values from a constructor in JavaScript?

AmitDiwan
Updated on 16-Jul-2020 07:10:03

190 Views

Following is the code for returning values from a constructor in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Returning value from constructor CLICK HERE Click on the above button to return a object from constructor    let resEle = document.querySelector(".result");    function Human(){       this.firstName = 'Rohan';       this.lastName = 'Sharma';       this.age = 22;     ... Read More

Creating JavaScript constructor using the “new” operator?

AmitDiwan
Updated on 16-Jul-2020 07:07:23

156 Views

Following is the code for creating a JavaScript constructor using the ‘new’ operator −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript constructor using new CLICK HERE Click on the above button to create JavaScript constructor using new operator    let resEle = document.querySelector(".result");    function Human(firstName, lastName, age){       this.firstName = firstName;       this.lastName = lastName;       this.age ... Read More

How to add a property, method to a JavaScript constructor?

AmitDiwan
Updated on 16-Jul-2020 07:05:10

229 Views

Following is the code to add a property, method to a JavaScript constructor −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       } Add property, method to javaScript constructor CLICK HERE Click on the above button to add property, method to constructor    let resEle = document.querySelector(".result");    function Human(firstName, lastName){       this.firstName = firstName;       this.lastName = lastName;    } ... Read More

How to add, access, delete, JavaScript object properties?

AmitDiwan
Updated on 16-Jul-2020 07:02:23

159 Views

Following is the code to add, access and delete JavaScript object properties −Example Live Demo

Add class (odd and even) in HTML via JavaScript?

AmitDiwan
Updated on 16-Jul-2020 07:26:08

622 Views

To add class, use nth-child(odd) and nth-child(even). Following is the code −Example Live Demo Document MongoDB Javascript Java MySQL    .subjectName:nth-child(odd) {       color: blue;    }    .subjectName:nth-child(even) {       color: purple;    } To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.Output

Range Overflow and Range Underflow properties in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 06:59:54

733 Views

Range Underflow − If the element value is less than that of the specified in min attribute, it sets to true.Range Overflow − If the element value is more than that of the specified in max attribute, it sets to true.Following is the code for Range overflow and range underflow property in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Range Overflow and Range Underflow property ... Read More

How to stop a function during its execution in JavaScript?

AmitDiwan
Updated on 16-Jul-2020 07:04:12

5K+ Views

To stop a function during its execution, use the concept of −document.getElementById().addEventListener().Example Live Demo Document Call the function Stop the function execution    document.getElementById("call").addEventListener("click", callFunction);    document.getElementById("halt").addEventListener("click", haltFunction);    var timeValue = null;    function callFunction() {       timeValue = setInterval(function() {          console.log("The call() is being executed....");       }, 1000);    }    function haltFunction() {       clearInterval(timeValue);    } To run the above program, save the file name anyName.html(index.html) and right click on the file and select ... Read More

How to convert JSON text to JavaScript JSON object?

AmitDiwan
Updated on 16-Jul-2020 06:57:01

866 Views

The JSON parse() method is used for converting a JSON text to a JavaScript object.Following is the code for converting JSON text to JavaScript JSON object −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JSON parse() Method {"name":"Rohan", "sports":["Cricket", "Football"], "country":"India"} CLICK HERE Click on the above button to parse the above JSON string    let ... Read More

Add oninput attribute to HTML element with JavaScript?

AmitDiwan
Updated on 16-Jul-2020 06:54:17

601 Views

For this, use the concept of document.getElementById() along with addEventListener(). Following is the JavaScript code −Example Live Demo Document Enter the value:    document.getElementById('enterValue').addEventListener("input", function () {       console.log('you have entered the value');    }); To run the above program, save the file nameanyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.OutputWhen user enters a value −

How to create a JSON object in JavaScript? Explain with an example.

AmitDiwan
Updated on 16-Jul-2020 06:54:14

474 Views

Following is the code to create a JSON object in JavaScript.Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JSON object in JavaScript JSON OBJECT CLICK HERE Click on the above button to create a JSON object and display it    let resEle = document.querySelector(".result");    let obj = {       firstName:'Rohan',       lastName: 'Sharma',       Age:14,    }    document.querySelector(".Btn").addEventListener("click", () => {       for(i in obj){          resEle.innerHTML += 'key = '+i+' value = ' + obj[i] + '';       }    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Advertisements