Articles on Trending Technologies

Technical articles with clear explanations and examples

How to use JavaScript variables in jQuery selectors?

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

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 More

What is the JavaScript version of sleep()?

Alankritha Ammu
Alankritha Ammu
Updated on 11-Mar-2026 462 Views

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 More

When should I use an Inline script and when to use external JavaScript file?

Sai Subramanyam
Sai Subramanyam
Updated on 11-Mar-2026 2K+ Views

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 More

How to escape square brackets in jQuery selector?

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

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 More

How to wrap and unwrap HTML control with a div dynamically using jQuery?

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

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 More

How to Scroll to the top of the page using JavaScript/ jQuery?

Anjana
Anjana
Updated on 11-Mar-2026 308 Views

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 More

How to turn a String into a JavaScript function call?

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

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 More

How to use variable number of arguments to function in JavaScript?

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

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 More

How to get objects by ID, Class, Tag, and Attribute in jQuery?

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

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 More

How can I bind all events on a DOM element using jQuery?

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

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
Showing 381–390 of 61,248 articles
« Prev 1 37 38 39 40 41 6125 Next »
Advertisements