Found 9150 Articles for Object Oriented Programming

Can I verify if a JavaScript variable is loaded if so, how?

AmitDiwan
Updated on 18-Jul-2020 07:26:35

2K+ Views

To verify if a JavaScript variable has been loaded or not, we can check if it is undefined or has a null value by doing comparison for both the values. We can also use typeof() since it returns string always to know if variable has been loaded or not.Following is the code to verify if a JavaScript variable has been loaded or not −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;   ... Read More

How to get the child element of a parent using JavaScript?

AmitDiwan
Updated on 18-Jul-2020 07:19:35

566 Views

Following is the code for getting the child element of a parent using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .child1,    .child2,    .child3 {       display: none;       margin: 10px;       width: 70px;       height: 70px;    }    .child1 {       background-color: red;    }    .child2 {       background-color: pink;    }    .child3 {       background-color: blue;    } Get ... Read More

What are the uses of the JavaScript WITH statement?

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

1K+ Views

The WITH statement is used to specify the default object for the given property and allow us to prevent writing long lengthy object references. It adds the given object to the head of the scope chain.Following is the code for with statement in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript with statement CLICK HERE Click on the above button to get the first ... Read More

Accessing a parent Element using JavaScript

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

493 Views

Following is the code for accessing a parent element using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: #8a2be2;    }    .parent1,    .parent2,    .parent3 {       display: inline-block;       margin: 10px;    }    .child1,    .child2,    .child3 {       width: 70px;       height: 70px;    }    .child1 {       background-color: red; ... Read More

How to check whether a Button is clicked with JavaScript?

AmitDiwan
Updated on 18-Jul-2020 07:14:56

1K+ Views

Following is the code for checking whether a button is clicked using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Checking whether a Button is clicked using JavaScript CLICK HERE Click on the above button to check if the button is clicked    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let clickCount = 0;    BtnEle.addEventListener("click", () => {       clickCount++;       resEle.innerHTML =       "The button has been clicked " + clickCount + " times ";    }); OutputOn clicking the button 5 times −

JavaScript code to extract the words in quotations

Disha Verma
Updated on 13-Mar-2025 13:06:54

385 Views

Extracting text enclosed in quotation marks is a common task in programming, especially when working with strings that include quotes. In JavaScript, strings are a data type used to represent text. A string is a sequence of characters enclosed in single quotes ('), double quotes ("), or backticks (`). In JavaScript, strings are a data type used to represent text. JavaScript provides multiple ways to extract text enclosed in quotation marks. This article explains how to extract words or phrases inside quotations from a string efficiently. Extracting text enclosed in quotation marks Extracting text enclosed in quotation marks can ... Read More

Alert for unsaved changes in form in JavaScript

AmitDiwan
Updated on 18-Jul-2020 07:13:19

705 Views

Following is the code to display an alert for form’s unsaved changes in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    input {       margin: 10px;    } Alert for unsaved changes in form Username Password SUBMIT    function pageUnload() {       return "The data on this page will be lost if you leave";    } OutputIf we click on the reload button then the following warning will be shown −

JavaScript code to find the coordinates of every link in a page

AmitDiwan
Updated on 18-Jul-2020 07:12:52

186 Views

Following is the code to find the coordinates of every link in a page using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500; } Coordinates of every link in a page google.com facebook.com yahoo.com CLICK HERE Click on the above button to display the link coordinates    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let links = document.getElementsByTagName("a");    BtnEle.addEventListener("click", () ... Read More

Circle coordinates to array in JavaScript

AmitDiwan
Updated on 18-Jul-2020 07:11:39

465 Views

Following is the code to circle coordinates to array in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-weight: 500;       font-size: 18px;       color: blueviolet;    } Circle coordinates to array CLICK HERE Click on the above button to generate the circle coordinates    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let xCoords = [];    let yCoords = [];    function circleCoordinates(radius, steps, ... Read More

Program to retrieve the text contents of the user selection using JavaScript.

AmitDiwan
Updated on 18-Jul-2020 07:08:57

127 Views

Following is the code to retrieve the text contents of the user selection using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;       color: rebeccapurple;    } Retrieve the text contents of the user selection Here is some text inside the div SELECT Click on the above button to display the text selected by the user    let resEle = document.querySelector(".result"); ... Read More

Advertisements