Articles on Trending Technologies

Technical articles with clear explanations and examples

Which one is better to use for a JavaScript link, “#” or “javascript:void(0)”?

Smita Kapse
Smita Kapse
Updated on 11-Mar-2026 236 Views

Using “javascript:void(0)” is definitely better, since its faster. Try to run both the examples in Google Chrome with the developer tools. The “javascript:void(0)” method takes less time than the only #.Here’s the usage of “javascript: void(0)”:If inserting an expression into a web page results in an unwanted effect, then use JavaScript void to remove it. Adding “JavaScript:void(0)”, returns the undefined primitive value.The void operator is used to evaluate the given expression. After that, it returns undefined. It obtains the undefined primitive value, using void(0).The void(0) can be used with hyperlinks to obtain the undefined primitive valueExample       ...

Read More

How to set a cookie and get a cookie with JavaScript?

Sreemaha
Sreemaha
Updated on 11-Mar-2026 4K+ Views

Set CookieThe simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this:document.cookie = "key1=value1;key2=value2;expires=date";Here the “expires” attribute is optional. If you provide this attribute with a valid date or time, then the cookie will expire on a given date or time and thereafter, the cookies' value will not be accessible.ExampleTry the following. It sets a customer name in an input cookie.                                                  Enter name: ...

Read More

How to move an element of an array to a specific position (swap)?

Sharon Christine
Sharon Christine
Updated on 11-Mar-2026 3K+ Views

To move an element from one position to other (swap) you need to –Create a temp variable and assign the value of the original position to it.Now, assign the value in the new position to original position.Finally, assign the value in the temp to the new position.Exampleimport java.util.Arrays; public class ChangingPositions {    public static void main(String args[]) {       int originalPosition = 1;       int newPosition = 1;       int [] myArray = {23, 93, 56, 92, 39};       int temp = myArray[originalPosition];             myArray[originalPosition] = myArray[newPosition];       myArray[newPosition] = temp;       System.out.println(Arrays.toString(myArray));    } }Output[23, 39, 56, 92, 93]

Read More

How to access index of an element in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 11-Mar-2026 919 Views

To access the index of an element in jQuery, use the eq() method. The eq() method refers the position of the element.ExampleYou can try to run the following code to learn how to access index of an element in jQuery, $(document).ready(function(){    $('ul li').eq(2).css({'background-color':'#E6B16A'});});   India   US   UK   Australia

Read More

How to check which key has been pressed using jQuery?

Amit D
Amit D
Updated on 11-Mar-2026 850 Views

To check which key has been pressed, use the onkeydown attribute.ExampleYou can try to run the following code to get which key is pressed: Press a key in the below box to get which key is pressed.   function demoFunction(event) {     var a = event.key;     document.getElementById("test").innerHTML = "You've pressed the key: " + a;   }

Read More

How to access element with nth index in jQuery?

Ricky Barnes
Ricky Barnes
Updated on 11-Mar-2026 1K+ Views

To access element with nth index from an HTML page, use the jQuery eq() method. It is used to access the index of an element in jQuery. The eq() method refers the position of the element.ExampleYou can try to run the following code to access element with nth index in jQuery. Here, element with 2nd index is considered: $(document).ready(function(){    $('ul li').eq(2).css({'background-color':'#E6B16A'});});   India   US   UK   Australia

Read More

How to trigger the same function with jQuery multiple events?

Amit D
Amit D
Updated on 11-Mar-2026 5K+ Views

To trigger the same function with multiple events, use the jQuery on() method with multiple events such as click, dblclick, mouse enter, mouse leave, hover, etc.ExampleYou can try to run the following code to learn how to work the same function with jQuery multiple events: $(document).ready(function(){     $("p").on({             mouseenter: function(){             $(this).css("background-color", "gray");         },                   mouseleave: function(){             $(this).css("background-color", "red");         },                 dblclick: function(){             $(this).css("background-color", "yellow");         }             }); }); Click, double click and move the mouse pointer.

Read More

How to determine if an argument is sent to the JavaScript function?

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 149 Views

To determine if an argument is sent to function, use “default” parameters.ExampleYou can try to run the following to implement it                    function display(arg1 = 'Tutorials', arg2 = 'Learning') {             document.write(arg1 + ' ' +arg2+"");          }          display('Tutorials', 'Learning');          display('Tutorials');          display();          

Read More

How to change first and last elements of a list using jQuery?

Ricky Barnes
Ricky Barnes
Updated on 11-Mar-2026 826 Views

To change the first and last elements of a list use the eq() method.ExampleYou can try to run the following code to change first and last elements of a list using jQuery:    $(document).ready(function(){    $("#list li:eq(2)").after($("#list li:eq(0)"));  });     This year's ranking:   India   US   UK Last year's ranking:   India   US   UK

Read More

Is it possible to detect when images are loaded via a jQuery event?

Alex Onsman
Alex Onsman
Updated on 11-Mar-2026 2K+ Views

To detect loading of an image with jQuery, use the load() event handler.Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.ExampleYou can try to run the following code to learn how to detect when image loads: $(document).ready(function(){     $("img").load(function(){         alert("Image successfully loaded.");     }); }); Note: The load() method deprecated in jQuery version 1.8. It was completely removed in version 3.0. To see its working, add jQuery version for CDN before 3.0.

Read More
Showing 391–400 of 61,248 articles
« Prev 1 38 39 40 41 42 6125 Next »
Advertisements