Found 10483 Articles for Web Development

How are the times a user presses the button counted in jQuery?

AmitDiwan
Updated on 03-Oct-2020 13:23:41

171 Views

To count how many times a user presses the button, you need to set counter on button click.ExampleFollowing is the code − Live Demo            Document Press Me The current Value is= 0 var increment = 0; var current = document.getElementById('incrementThisValue'); document.getElementById('pressButton').onclick = (event) => {    current.textContent = ++increment; }; To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −When you press ... Read More

Display tooltip text while hovering a textbox in jQuery

AmitDiwan
Updated on 03-Oct-2020 13:18:42

2K+ Views

For this, use jQuery(selector).toolTip().ExampleFollowing is the code: − Live Demo            Document    Write Your Favourite Subject Name:        jQuery(".demoTooltip").toolTip() To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −When you will hover the mouse inside the text box, you will get your tooltip −Your Favourite Subject may be JavaScript...Displayed in the below screenshot as well −

Slide up and down of a div animates its content - jQuery?

AmitDiwan
Updated on 03-Oct-2020 13:13:52

461 Views

To toggle content, use slideToggle() in JavaScript.ExampleFollowing is the code: − Live Demo            Document    .firstDiv {       display: none;    }    .txtBox {       display: block;    }    Press Me to toggle the text box                              Enter your name:                        function toogleTheTextBox() {       $('#firstDiv').slideToggle(function () {          $('#txtBox').focus();       });    } To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThe output is as follows −Press the button “Press Me” to toggle the text box.OutputThe output is as follows −

Looping numbers with object values and push output to an array - JavaScript?

AmitDiwan
Updated on 03-Oct-2020 13:10:05

164 Views

Let’s say the following are our numbers with object values −var numberObject = { 2:90 , 6: 98 }Use Array.from() in JavaScript −var fillThePositionValue = Array.from({length: 15}, (value, index) => numberObject[index+ 1] || "novalue")ExampleFollowing is the code to loop numbers with object values −var numberObject = { 2:90 , 6: 98 } console.log("The actual object is="); console.log(numberObject); var fillThePositionValue = Array.from({length: 15}, (value, index) => numberObject[index+ 1] || "novalue") console.log("After filling the value, the actual object is="); console.log(fillThePositionValue)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo215.js.OutputThe output is as follows ... Read More

JavaScript - Check if value is a percentage?

Disha Verma
Updated on 25-Feb-2025 14:50:05

1K+ Views

To check the value for percentage, use a regular expression. When dealing with user input or processing data in JavaScript, it's important to make sure a value is a valid percentage. This article shows you how to check if a value is a percentage using JavaScript, highlighting a useful method that involves regular expressions. Let's say the following is our value var value="97%"; To check the value for percentage, we are using a regular expression. Using Regular Expression The best way to check if a string is in the correct percentage format is by using regular expressions. ... Read More

How to Implicitly mimic click() in jQuery?

AmitDiwan
Updated on 03-Oct-2020 12:57:04

168 Views

To implicitly mimic click(), you can call a function internally.ExampleFollowing is the code to implicitly mimic click − Live Demo            Document    My Name is John Doe            demo1Data = document.getElementById('demo1').innerHTML    demo1Data = demo1Data.replace('My Name is John Doe', `My Favourite Subject is JavaScript..`)    document.getElementById('demo2').innerHTML = demo1Data    function replaceData() {       document.getElementById('output').innerHTML = 'I live is US.';    } document.getElementById('demo2').querySelector('span').click(); To run the above program, save the file name anyName.html (index.html). Right click on the file and select ... Read More

How to enable the “disabled” attribute using jQuery on button click?

AmitDiwan
Updated on 03-Oct-2020 12:53:40

2K+ Views

Set the disabled property to true in jQuery −ExampleFollowing is the code − Live Demo         Document             $("#change").click(function (buttonEvent) {     buttonEvent.preventDefault();     $('#showTxtBoxHide').prop("disabled", false);   });   To run the above program, save the file name anyName.html(index.html). Right click on the file and select the option “Open with live server” in VS Code editor −OutputThe output is as follows −The text box property is disabled. To enable, you need to click the button −

Behavior of + operator in JavaScript to store large numbers?

AmitDiwan
Updated on 03-Oct-2020 12:38:27

3K+ Views

To store large numbers in JavaScript, use BigInt() rather than + operator. If you will use the + operator, then expect loss of precision.Let’s say the following is our large number and we are storing using BigInt() −console.log("Loss of precision with + operator..")ExampleFollowing is the code −var stringValue1="100"; console.log("The integer value="); console.log(+stringValue1); var stringValue2="2312123211345545367"; console.log("Loss of precision with + operator..") console.log(+stringValue2); const storeLongInteger=BigInt("2312123211345545367"); console.log("No loss of precision with BigInt()"); console.log(storeLongInteger);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo212.js.OutputThe output is as follows on console −PS C:\Users\Amit\JavaScript-code> node demo213.js The ... Read More

How to populate select list with jQuery?

AmitDiwan
Updated on 01-Oct-2020 13:42:21

11K+ Views

To populate select list with jQuery, use for loop along with append() and append the options to the already created select.Let’s say we have the following select with options − John David ExampleFollowing is the code to append more number of options using append() − Live Demo            Document           John       David     $(document).ready(function () {    var data = [       { "name": "Bob", "customerName": "Bob" },       { "name": "Mike", "customerName": "Mike" }    ];    for (var index = 0; index

Convert integer array to string array in JavaScript?

AmitDiwan
Updated on 01-Oct-2020 13:38:04

568 Views

To convert integer array to string array, use the map(String) in JavaScript. Let’s say the following is our integer array −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68];Convert integer array to string array −integerValues.map(String);ExampleFollowing is the code −var integerValues = [101, 50, 70, 90, 110, 90, 94, 68]; console.log("The integer array value="); console.log(integerValues); integerValues.map(String); console.log("The string array value="); console.log(integerValues)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo212.js.OutputThe output is as follows in console −PS C:\Users\Amit\JavaScript-code> node demo212.js The integer array value= [    101, 50, 70, 90, ... Read More

Advertisements