
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 6710 Articles for Javascript

884 Views
Following is the code for looping over regular expression matches in javaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; color: blueviolet; font-weight: 500; } .sample { color: red; } Looping over regex matches There is a cat lying besides the cricket bat and chasing the rat CLICK HERE Click on the above button to match words ... Read More

128 Views
In this tutorial, we will learn about the lastIndex property in javascript. In addition to this, we will also learn about how we can use it to manage matches within a string The lastIndex property is a property given by regex objects in JavaScript. It represents the index at which the next search will start within a string passed in the regex, or in simple terms, the index at which to start the next match in a string. When using a regex object with methods like exec(), compile(), etc, the lastIndex property is automatically updated to the index after the ... Read More

736 Views
A symbol in JavaScript is a primitive data type, introduced in ES6 version update, that represents an immutable and unique identifier. Unlike other primitive types like strings, booleans, numbers, etc, symbols are guaranteed to be unique. This implies that even if two symbols have the same content, they are going to be distinct (separate) entities and not equal to each other. Symbols are primarily used to avoid naming conflicts when adding properties to objects. In this Tutorial, we will learn about symbols in JavaScript. Along with that we will also learn how we can use them to add properties in ... Read More

354 Views
Following is the code to override derived properties in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Override derived properties Before overriding After overriding CLICK HERE Click on the above button to override the above properties let sampleEle = document.querySelector(".sample"); let resEle ... Read More

3K+ Views
Use document.getElementById().innerHTML for this. Following is the JavaScript code −Example Document function display(){ var storedValue = document.getElementById('getValue').innerHTML.value="This is the value"; console.log("The value is==="+storedValue); } To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.Following is the output. When you will click the mouse and place the arrow key, you will get the following output.The snapshot is as follows −

984 Views
The onchange event triggers when an element changes. You need to use below syntax.onchange="yourFunctionName(this);"Example Live Demo Document Choose Color function showValue(c){ console.log(c.value); } To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.OutputAfter clicking the input type color, you will get the color value in console −

290 Views
Following is the JavaScript code to make a format like ABC-1234 −Example Live Demo Document ABC1234 function joinTheDashSymbol(m, r1,r2,r3,r4,r5) { if (r1) return [r1,r2,r3].join('-'); else return [r4,r5].join('-'); } $(".formatting").text(function(i, words) { words = words.replace(/^(\d{3})(\d{3})(\d{4})|([A-Z]{3})(\d{4})$/, joinTheDashSymbol); return words; }); To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.Output

519 Views
A default search text is a text that provides suggestions or a hint of what to search for in the search (input) box. Following is an illustration of a search box, where you can observe a default search text "Search your favorite tutorials…" : The above default search text will suggest to visitors that they can search for their favorite tutorial, which they want to read or open on the website. Adding Default Search Text to Search Box Using JavaScript In HTML, the text (i.e., search text) that appears inside a search box or input field before the user ... Read More

485 Views
Display in alert by using alert(window()). Following is the syntax −alert(window['yourVariableName' + 'yourVariableName' + otherVariableName]);Example Live Demo Document var globalVariablelocal_print100=100; print100=1; alert(window['globalVariable' + 'local_' + print100]); To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.Output

4K+ Views
You can use the concept of value(). Following is the JavaScript code −Example Live Demo Document FirstNumber SecondNumber: Add Two Nnumbers The addition is: function add() { var f = parseInt(document.getElementsByName('input1')[0].value);` var s =parseInt(document.getElementsByName('input2')[0].value); var result = f+s; document.getElementsByName('display')[0].value= result; } To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS code editor.OutputOn clicking the button, the value will be displayed in the textbox. The snapshot is as follows −