Javascript Articles

Page 60 of 534

How to disable default behavior of <input type=“time”> when you press enter with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 374 Views

For this, you need to use keyDown as well as preventDefault(). Following is the JavaScript code −Example Document    const pressEnter = (event) => {       if (event.key === "Enter") {          event.preventDefault();       }    };    document.getElementById("disableDefaultTime").addEventListener("keydown",    pressEnter); To run the above program , just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VSCode editor.OutputFollowing is the output. When you press Enter key nothing will be displayed.You need to use keyDown to get time as in the below screenshot −

Read More

How can I disable JavaScript click function if link starts with #?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 447 Views

For this, use preventDefault() in JavaScript. Following is the JavaScript code −Example Document Press Me to see logs Press Me to see logs in console Nothing will happen    $(function(){       $("a:not([href='#'])").click(function(event){          event.preventDefault();          console.log("You have pressed me!!!!!");       });    }); To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option Open with live server in VS code editor.OutputIf you click the two links, Press Me to ...

Read More

Unicode Property Escapes JavaScript Regular Expressions

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 238 Views

The Unicode property escapes regular expressions, allow us to match characters based on their Unicode properties by using the flag u.ExampleFollowing is an example − Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500; } Unicode Property Escapes JavaScript Regular Expressions Hello 😆😀 World 🙂😊 CLICK HERE Click on the above button to extract the emojis using regex    let sampleEle = document.querySelector(".sample").innerHTML;    let btnEle = ...

Read More

Lookbehind Assertions JavaScript Regular Expressions

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 188 Views

Lookbehind allows matching a pattern only if there’re something before.Following is an example −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } Look behind Assertions Regular Expressions The price for 4 tables are $50 , $99 , $121 and $150. CLICK HERE Click on the above button to extract the table price using lookbehind    let sampleEle = document.querySelector(".sample").innerHTML;    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    const priceRegex=/(? {       resEle.innerHTML = "Table price are = "+sampleEle.match(priceRegex);    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More

Named capture groups JavaScript Regular Expressions

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 215 Views

With JavaScript, you can group s part of regular expression. This can be done by encapsulating characters in parentheses.Following is an example −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } Named capture groups Regular Expressions The year in which i passed school was 2012. CLICK HERE Click on the above button to extract the year using named groups    let sampleEle = document.querySelector(".sample").innerHTML; ...

Read More

Explain the callback Promise.finally in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 239 Views

The promise.finally() calls the callback function whether a promise has been fulfilled or rejected. This helps us to do something once the promise has been rejected or resolved.Following is the code for Promise.finally() in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Promise.finally in JavaScript CLICK HERE Click on the above button to know when the promise finishes    let btnEle = document.querySelector(".btn"); ...

Read More

Explain ‘dotAll’ flag for regular expressions in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 282 Views

The dotAll flag returns true or false depending upon if the s flag has been set in the regular expression or not.Following is the code to implement dotAll flag for regular expressions in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } dotAll flag for regular expressions CLICK HERE Click on the above button to know if s flag has been set in regex or not ...

Read More

How to import and export a module/library in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

Note − To run this example you will need to run a localhost server.Following is the code for importing and exporting a module/library in JavaScript −ExampleINDEX.html Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } JavaScript Importing and Exporting Modules IMPORT Click on the above button to import module script.jsimport test from './sample.js'; document.querySelector('.Btn').addEventListener('click',()=>{    test(); })sample.jslet resultEle = document.querySelector(".result"); export default function testImport(){    resultEle.innerHTML = 'Module testImport has been imported'; }OutputThe above code will produce the following output −On clicking the ‘IMPORT’ button −

Read More

NaN and Infinity example in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 251 Views

Following is the code to implement NaN and Infinity in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } NaN and Infinity in JavaScript CLICK HERE Click on the above button to see nan and infinity example    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    btnEle.addEventListener("click", () => {       resEle.innerHTML = "9/0 = " + 9 / 0 + "";       resEle.innerHTML += 'Number("AJKL") = ' + Number("AJKL") + "";    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More

How to search for a string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 292 Views

Following is the code for searching a string in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Searching a string in JavaScript The spring season is about to come. CLICK HERE Click on the above button to find the string 'spring' in the above string    let btnEle = document.querySelector(".btn");    let sampleEle = document.querySelector(".sample").innerHTML;    let resEle = document.querySelector(".result");    btnEle.addEventListener("click", () => {       resEle.innerHTML = "The string spring is found at position " + sampleEle.search("spring");    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Read More
Showing 591–600 of 5,338 articles
« Prev 1 58 59 60 61 62 534 Next »
Advertisements