Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
How can I pass a parameter to a setTimeout() callback?
To pass a parameter to setTimeout() callback, use the following syntax −setTimeout(functionname, milliseconds, arg1, arg2, arg3...)The following are the parameters −function name − The function name for the function to be executed.milliseconds − The number of milliseconds.arg1, arg2, arg3 − These are the arguments passed to the function.ExampleYou can try to run the following code to pass a parameter to a setTimeout() callback Submit function timeFunction() { setTimeout(function(){ alert("After 5 seconds!"); }, 5000); } Click the above button and wait for 5 seconds.
Read MoreHow to fire jQuery events with setTimeout?
The jQuery setTimeout() method is used to set an interval for events to fire.ExampleHere, we will set an interval of 3 seconds for an alert box to load using jQuery events: $(document).ready(function(){ $("#button1").click(function(){ setTimeout("alert('Hello World!');", 3000); }); }); Click Click the above button and wait for 3 seconds. An alert box will generate after 3 seconds.
Read MoreHow we can prioritize jQuery events?
To prioritize jQuery events, use the event.stopPropagation().ExampleYou can try to run the following code to learn how to prioritize using stopPropogation() method: $(document).ready(function(){ var timer; function out(s) { if (timer) { clearTimeout(timer); timer = null; } $("#demo").append(s + ""); timer = setTimeout(function() { $("#demo").append("-------" + ""); timer = null; }, 100); } $(".li").find('input').click(function(e){ out('li>input'); if ($(this).parent().hasClass("stop")) { e.stopPropagation(); } }); $(".li").click(function(e){ out('li'); }); $('input').click(function(e){ out('input'); if ($(this).parent().hasClass("stop")) { e.stopPropagation(); } }); }); Demo Demo using stop propagation method
Read MoreHow to set text font family in HTML?
To change the text font family in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML tag, with the CSS property font-family. HTML5 do not support the tag, so the CSS style is used to add font size.Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML tag or external style sheet.ExampleYou can try to run the following code to change the text font family in an HTML page ...
Read MoreWhich jQuery events do not bubble?
Some of the jQuery events, do not bubble such as mouseenter do not bubble. Let us see an example of such events.ExampleYou can try to run the following code to learn how to work with jQuery events, which do not bubble, $(document).ready(function(){ $("p").mouseenter(function(){ $("p").css("background-color", "red"); }); $("p").mouseleave(function(){ $("p").css("background-color", "blue"); }); }); Demo Text - Keep the mouse pointer here.
Read MoreHow to store and reproduce jQuery events?
To store and reproduce jQuery events, use console to log.ExampleYou can try to run the following code to learn how to store and reproduce jQuery events: $(document).ready(function(){ window.events = [] $("#track").click(function(event){ window.events.push(event) $.each(window.events, function(i, item){ console.log(i, item); }); }); }); Track
Read MoreHow to implement custom events in jQuery?
Custom event means you can create your own events in jQuery. For example, create a custom event to fire an alert box on pressing any key on the keyboard.ExampleYou can try to run the following code to learn how to create a custom event, $(document).ready(function(){ $('textarea').bind("enterKey",function(e){ alert("You have pressed Enter key!"); }); $('textarea').keyup(function(e){ if(e.keyCode == 13) { $(this).trigger("enterKey"); } }); });
Read MoreWhat is the sequence of jQuery events triggered?
The jQuery event handlers always execute in the order they were bound. With jQuery, you can also change the sequence. Let’s see how, for example, fromdemo(1); demo(2);We can change the sequence to −demo(2); demo(1);ExampleYou can try to run the following to learn and change the sequence of jQuery events − $(document).ready(function(){ $.fn.bindFirst = function(name, fn) { this.on(name, fn); this.each(function() { var handlers = $._data(this, 'events')[name.split('.')[0]]; var handler = handlers.pop(); ...
Read MoreHow to add a number of months to a date using JavaScript?
To add a number of months to a date, first get the month using getMonth() method and add a number of months.ExampleYou can try to run the following code to add a number of months var d, e; d = new Date(); document.write(d); e = d.getMonth()+1; document.write("Incremented month = "+e);
Read MoreHow to Convert a Java 8 Stream to an Array?
To convert a stream to an Array in Java -Collect the stream to a list using the Collect interface and the Collectors class.Now convert the list to an array using the toArray() method.Exampleimport java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class J8StreamToArray { public static void main(String args[]) { String[] myArray = { "JavaFX", "OpenCV", "WebGL", "HBase" }; Stream stream = Stream.of(myArray); List list = stream.collect(Collectors.toList()); String[] str = list.toArray(new String[0]); System.out.println(Arrays.toString(str)); } }Output[JavaFX, OpenCV, WebGL, HBase]
Read More