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 to wrap and unwrap HTML control with a div dynamically using jQuery?
To wrap html control, use the wrap() method and unwrap() method to unwrap html control.ExampleYou can try to run the following code to wrap and unwrap html control with a div dynamically using jQuery. $(document).ready(function(){ $("#button1").click(function(){ $("p").wrap(""); }); $("#button2").click(function(){ $("p").unwrap(); }); }); div { background-color: gray; } This is demo text. This is another text. Wrap Unwrap
Read MoreHow to Scroll to the top of the page using JavaScript/ jQuery?
Example $("a").click(function() { $("html, body").animate({ scrollTop: 0 }, "slow"); return false; }); TOP OF PAGE This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo ...
Read MoreHow to turn a String into a JavaScript function call?
To turn a string into a JavaScript function call, try to run the following codeExample function myFunction(argument) { alert('My function ' + argument); } functionName = 'myFunction'; window[functionName]('is working.');
Read MoreHow to use variable number of arguments to function in JavaScript?
To use a variable number of arguments to function, use the arguments object.ExampleYou can try to run the following code to implement arguments to a function in JavaScript function functionArgument(val1, val2, val3) { var res = ""; res += "Expected Arguments: " + functionArgument.length; res += ""; res += "Current Arguments : " + arguments.length; res += ""; res += "Each argument = " for (p = 0; p < arguments.length; p++) { res += ""; res += functionArgument.arguments[p]; res += " "; } document.write(res); } functionArgument(20, 50, 80, "Demo Text!","Hello World", new Date())
Read MoreHow to get objects by ID, Class, Tag, and Attribute in jQuery?
Here’s how you can get objects by ID Selector (#id), by Class Selector (.class), by Tag, and Attribute (.attr()).Get Object by Class SelectorExampleThe element class selector selects all the elements which match with the given class of the elements. jQuery Selector $(document).ready(function() { $(".big").css("background-color", "yellow"); }); This is first division ...
Read MoreHow can I bind all events on a DOM element using jQuery?
The bind( type, [data], fn ) method binds a handler to one or more events (like click) for each matched element. It can also bind custom events.Possible event values − blur, focus, load, resize, scroll, unload, click etc.Here is the description of all the parameters used by this method −type − One or more event types separated by a space.data − This is optional parameter and represents additional data passed to the event handler as event.data.fn − A function to bind to the event on each of the set of matched elements.ExampleYou can try to run the following code to learn how to ...
Read MoreWhat is "function*" in JavaScript?
The function* declaration is used to define a generator function. It returns a Generator object. Generator Functions allows execution of code in between when a function is exited and resumed later. So, generators can be used to manage flow control in a code.SyntaxHere’s the syntax −function *myFunction() {} // or function* myFunction() {} // or function*myFunction() {}Let’s see how to use generator functionExample function* display() { var num = 1; while (num < 5) yield num++; } var myGenerator = display(); document.write(myGenerator.next().value); document.write(""+myGenerator.next().value); document.write(""+myGenerator.next().value); document.write(""+myGenerator.next().value); document.write(""+myGenerator.next().value);
Read MoreHow to check the element type of an event target with jQuery?
To check the element type pf an event target, using the is() method.ExampleYou can try to run the following code to check the element type: $(document).ready(function(){ $( "ul" ).click(function( event ) { var target = $( event.target ); if ( target.is( "li" ) ) { alert("Element is 'li'") } }); }); Click below to find out which element India US UK
Read MoreWhat is the use of JavaScript eval function?
The JavaScript eval() is used to execute an argument. The code gets execute slower when the eval() method is used. It also has security implementations since it has a different scope of execution. In addition, use it to evaluate a string as a JavaScript expression.The eval() method is not suggested to use in JavaScript since it executes slower and improper usage opens your website to injection attacks.ExampleHere’s how you can implement eval() function var a = 30; var b = 12; var res1 = eval("a * b") + ""; var res2 = eval("5 + 10") + ""; document.write(res1); document.write(res2);
Read MoreWhat is an Event Object in jQuery?
The callback function takes a single parameter; when the handler is called the JavaScript event object will be passed through it.The event object is often unnecessary and the parameter is omitted, as sufficient context is usually available when the handler is bound to know exactly what needs to be done when the handler is triggered, however there are certain attributes which you would need to be accessed.Let us see an example of isDefaultPrevented() method. The isDefaultPrevented() method checks whether event.preventDefault() was ever called on this event object.ExampleYou can try to run the following code to learn how to work with ...
Read More