AmitDiwan has Published 10744 Articles

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

AmitDiwan

AmitDiwan

Updated on 15-Jul-2020 12:57:55

408 Views

For this, use preventDefault() in JavaScript. Following is the JavaScript code −Example Live Demo 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(); ... Read More

Unicode Property Escapes JavaScript Regular Expressions

AmitDiwan

AmitDiwan

Updated on 15-Jul-2020 12:56:25

207 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 − Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result ... Read More

Rest and Spread operators in JavaScript

AmitDiwan

AmitDiwan

Updated on 15-Jul-2020 12:53:19

6K+ Views

The rest operator (…) allows us to call a function with any number of arguments and then access those excess arguments as an array. The rest operator also allows us in destructuring array or objects.The spread operator (…) allows us to expand an iterable like array into its individual elements.ExampleFollowing ... Read More

Adding options to a when you press enter with JavaScript?

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 17:18:15

325 Views

For this, you need to use keyDown as well as preventDefault(). Following is the JavaScript code −Example Live Demo Document    const pressEnter = (event) => {       if (event.key === "Enter") {          event.preventDefault(); ... Read More

jQuery .val change doesn't change input value?

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 17:17:38

3K+ Views

For this, you need to use attr(). The attr() method can be used to either fetch the value of an attribute from the first element in the matched set or set attribute values onto all matched elements.Following is the JavaScript code −Example Live Demo ... Read More

Preconditions - Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 07:08:28

270 Views

Precondition to check if the list passed as parameter is empty or not. Let us see an example −Examplepublic void my_fun(List myList){    if (myList == null){       throw new IllegalArgumentException("List is null");    }    if (myList.isEmpty()){       throw new IllegalArgumentException("List is empty");    } ... Read More

Killing threads in Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 07:00:12

362 Views

Example Live Demopublic class Main{    static volatile boolean exit = false;    public static void main(String[] args){       System.out.println("Starting the main thread");       new Thread(){          public void run(){             System.out.println("Starting the inner thread");         ... Read More

Joiner class Guava Java

AmitDiwan

AmitDiwan

Updated on 14-Jul-2020 06:58:05

116 Views

Joiner provides various methods to handle joining operations on string, objects, etc. Let us see an example −Exampleimport com.google.common.base.Joiner; import java.util.*; public class Demo{    public static void main(String[] args){       String[] my_arr = { "hel", null, "lo", "wo", "r", null, "ld" };       System.out.println("The original ... Read More

Advertisements