Found 6710 Articles for Javascript

JavaScript to parse and show current time stamp of an HTML audio player.

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

1K+ Views

Following is the code to to parse and show current time stamp of an HTML audio player −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Show Current time stamp of an HTML audio player CLICK HERE Click on the above button to get the audio timestamp    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let audioEle = document.querySelector(".audio");    BtnEle.addEventListener("click", () ... Read More

Explain JavaScript eval() function what are the rules to be followed while using it.

AmitDiwan
Updated on 18-Jul-2020 07:28:58

134 Views

The eval() function is used to evaluate the given string and execute it as JavaScript code. Using eval() is highly dangerous as someone can pass malicious code as input string to one of out inputs.Following is the code to show eval() function in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript eval() function CLICK HERE Click on the above button to see eval() usage ... Read More

What's the best way to open new browser window using JavaScript?

AmitDiwan
Updated on 18-Jul-2020 07:28:53

253 Views

The open() method of window object is the best way to open new browser window using JavaScriptFollowing is the code for opening new browser window using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Open new browser window using JavaScript CLICK HERE Click on the above button open a new browser window    let BtnEle = document.querySelector(".Btn");    BtnEle.addEventListener("click", (event) => {       window.open("https://www.google.com");    }); OutputOn clicking the ‘CLICK HERE’ button, it will redirect to the specified website −

How to pass arguments to anonymous functions in JavaScript?

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

1K+ Views

Following is the code for passing arguments to anonymous functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-weight: 500;       font-size: 20px;       color: blueviolet;    } Pass arguments to anonymous functions CLICK HERE Click on the above button to call an anonymous function and pass parameters to it    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let add = function (a, b) {       return a + b;    };    BtnEle.addEventListener("click", (event) => {       resEle.innerHTML = "The sum of 22 and 19 = " + add(22, 19);    }); OutputOn clicking the ‘CLICK HERE’ button −

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

568 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

386 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

Advertisements