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 use JavaScript variables in jQuery selectors?
It’s quite easy to use JavaScript variables in jQuery selectors.ExampleLet’s seen an example to use JavaScript variables in jQuery to hide an element: $(document).ready(function(){ $("input").click(function(){ var name = this.name; $("input[name=" + name + "]").hide(); } ); }); Heading 1 To hide the buttons, click on it.
Read MoreWhat is the JavaScript version of sleep()?
The JavaScript version of sleep() is “await”. The await feature pauses the current aync function.ExampleYou can try to run the following code to implement sleep in JavaScript function setSleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function Display() { document.write('Wait for 5 seconds!'); await setSleep(5000); document.write('After 5 seconds!'); } Display();
Read MoreWhen should I use an Inline script and when to use external JavaScript file?
To enhance performance, try to keep JavaScript external. The separate code makes it easier for web browsers to cache. However, use inline scripts only when you’re making single page websites. Still, it's better to use external code i.e. external JavaScript. To place JavaScript in external file create an external JavaScript file with the extension .js. After creating, add it to the HTML file in the script tag. The src attribute is used to include that external JavaScript file. If you have more than one external JavaScript file, then add it to the same web page to increase the performance of ...
Read MoreHow to escape square brackets in jQuery selector?
To escape square brackets in jQuery selectors is quite easy. Let’s see with an example of escaping the brackets in the name of the box.ExampleWhatever you will select, will get added to the textarea on button click. $(document).ready(function() { $("#addnow").click(function () { $("#myselect :selected").each(function () { $("#text").val($("#text").val() + $(this).text() + ""); }); }); }); email@example.com David Select and Click to Add
Read MoreHow 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 More