- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9297 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
169 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 −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
770 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 −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
455 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
409 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
925 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 −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
304 Views
Following is the code to extract the words in quotations 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: red; } Extract the words in quotations Hello "World" CLICK HERE Click on the above button to get the text between quotes let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let sampleEle = document.querySelector(".sample"); let regex = /"(.*?)"/g; var match = regex.exec(resEle.innerHTML); BtnEle.addEventListener("click", () => { if (match) { sampleEle.innerHTML += match[0]; } }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
624 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 −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
117 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