Found 6710 Articles for Javascript

JavaScript focus a particular element with div class, not div id declaration?

Alshifa Hasnain
Updated on 04-Mar-2025 19:49:21

2K+ Views

In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript setting focus on an element is commonly done using the focus() method. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the DOM element that will receive the focus. Using JavaScript to Focus on a Class Element ... Read More

Highlight a text, every time page loads with JavaScript

AmitDiwan
Updated on 16-Jul-2020 07:33:13

311 Views

To highlight a text, every time page loads, use the for loop and the concept of −Example Live Demo Document    .yellow {       color: yellow;    }    .blue {       color: blue;    } My yellow Words, your blue Words    var ids = document.getElementById("pageLoads");    var loadColorWords = ids.innerHTML.split(" ");    for(var i = 0; i < loadColorWords.length; i++) {       if(loadColorWords[i] == "blue") {          loadColorWords[i] = "" + loadColorWords[i] + "";       } ... Read More

Window innerWidth and innerHeight Properties in JavaScript.

AmitDiwan
Updated on 16-Jul-2020 07:37:06

182 Views

The innerWidth property returns the width of the window content area and the innerHeight property returns the width of the window content area.Following is the code for window innerWidth and innerHeight properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result{       font-size: 20px;       font-weight: 500;    } Window innerWidth and innerHeight Properties CLICK HERE Click on the above button get the innerWidth and innerHeight of the window.    let ... Read More

Type casting in JavaScript.

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

8K+ Views

Type casting means conversion of one data type to another explicitly. In JavaScript some of the most common methods to convert a datatype to either string using String(), to boolean using Boolean(), or to number using Number().Following is the code for type casting in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Type casting in JavaScript. 44 CLICK HERE Click on the above button ... Read More

What is JavaScript type coercion?

AmitDiwan
Updated on 16-Jul-2020 07:17:18

221 Views

Type coercion means conversion of a datatype to another automatically or implicitly.Following is the code for JavaScript type coercion −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 20px;       font-weight: 500;    } JavaScript type coercion 22 CLICK HERE Click on the above button to add the above number with 5.    let sampleEle = document.querySelector('.sample');    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {       resEle.innerHTML = ' "22" + 5 = ' + sampleEle.innerHTML+5;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Explain the finally Statement in JavaScript with examples.

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

175 Views

The finally statement always executes after try and catch block regardless of if there was an error or not.Following is the code for the finally statement in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Finally in Javascript CLICK HERE Click on the above button to call a variable before it is defined    let sampleEle = document.querySelector(".sample");    let ... Read More

Returning values from a constructor in JavaScript?

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

187 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

153 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

224 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

154 Views

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

Advertisements