Articles on Trending Technologies

Technical articles with clear explanations and examples

Returning values from a constructor in JavaScript?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 217 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
AmitDiwan
Updated on 16-Jul-2020 187 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
AmitDiwan
Updated on 16-Jul-2020 260 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 stop a function during its execution in JavaScript?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 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 add, access, delete, JavaScript object properties?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 188 Views

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

Read More

Range Overflow and Range Underflow properties in JavaScript.

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 791 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

Add oninput attribute to HTML element with JavaScript?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 640 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 −

Read More

Get number from user input and display in console with JavaScript

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 3K+ Views

You can use # to get the value when user clicks the button using document.querySelector(“”); Following is the JavaScript code −Example Live Demo Document Example: choose a number between 1 to 100 Give a number: Click Me    function example() {       let btn = document.querySelector("#choose");       let randomNumber = Math.ceil(Math.random() * 100);       btn.onclick = function() {          let givenNumber = document.querySelector("#inputNumber").value;          let valueInt = parseInt(givenNumber, 100);   ...

Read More

How to create a constant array in JavaScript? Can we change its values? Explain.

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 2K+ Views

To create a const array in JavaScript we need to write const before the array name. The individual array elements can be reassigned but not the whole array.Following is the code to create a constant array in JavaScript.Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Const array in JavaScript CLICK HERE Click on the above button to change array values and reassign the ...

Read More

Hide div that contains specific text with JavaScript?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 2K+ Views

At first, you need to extract the extract the div class with the help of getElementsByClassName() and iterate over the for loop and use the OR condition to show the specific text.Also, set yourDiv.style.display=’none’.Following is the JavaScript code −Example Live Demo Document header content footer    let attribute = document.getElementsByClassName('block');    for (let i = 0; i < attribute.length; i++) {       let impDiv = attribute[i];       let value = impDiv.innerHTML.trim();       if (value == 'header' || value == ...

Read More
Showing 40651–40660 of 61,248 articles
Advertisements