setTimeout function jQuery

If you are thinking to perform some operation(s) after some specified interval of time, then jquery setTimeout function is ready to do the job for you.

setTimeout function

setTimeout() accepts two arguments.

  1. The function that you want to execute after specified delay.
  2. The duration of delay in milliseconds

In the above example code, myFunction is the one which I wanted to execute after 2 seconds.

In another way, one can also use anonymous function(if not want to define the function separately) and define login in setTimeout as follows:

setTimeout() is a basic JavaScript function, actually. Do not confuse setTimeout() with setInterval() function. The difference between the two is that setTimeout() executes once after specified time, while setInterval() repeats the execution of function.

Read More

Get URL parameter using jQuery

With the help of jquery we can easily extract or get URL parameter. This post contains the jquery code which can be used to get URL parameter.

jQuery Script to get URL parameter

This script will help you in extracting the required parameter from URL. The function getUrlParameter() is responsible for extracting parameters from URL and returning the value of required paramater, if found.


For example, you have the following URL

Now you want to find message and its value. Call the function getUrlParamter() and pass the string “message”. The function will extract parameters from current URL will match “message” will each. A value will be returned if “message” parameter is found.


Read More

select one element from same class using jquery

At times, you may come across a situation when you need to select one element from same class. jQuery makes is very simple to select an element from same class.

Lets setup an example of five paragraph which share same class.

Now, we want to change the color of third paragraph, only. Following script will work for us.

:eq() is one of the index-selectors. Other index-selector are :lt() :gt() :odd() :even. Try to play with them ,too.



eq-selector @


Read More

Download file using jQuery / JavaScript

In this article, we will share a simple script about how to download file using jQuery or JavaScript. Example will focus on jQuery click event.

Suppose we have a button or a link which has id=”download_file”.


We want to download the file when a user clicks on this button.


This is a very simple script about how to download file using jQuery / JavaScript.



Read More

jQuery click not working on dynamic content [solution]

jQuery click not working? Follow this article to find a solution.

Sometimes you may come across an issue where jquery event does not work on an element, which is generated dynamically via jQuery. For example, if you have any HTML element on which you click to create/append some other HTML element, jQuery click will not work on the appended or dynamically created element on the page.

If the code is not working on dynamically created content, the code might be as follows.

.class_name is actually the name of class of the element that was generated by jQuery, dynamically.

In such case, you will have to modify your code a bit in the following way.

This change in code has always worked for me whenever I wanted to trigger a function on the event or simply click event upon dynamically created content. I hope this will work you, too.

For further study:

Jquery event handler not working on dynamic content

Read More


The following script shows how to auto-set the format of CNIC number using jQuery while typing in the input field.

Format of CNIC is xxxxx-xxxxxxx-x

While typing numbers of your CNIC, “-” should be automatically inserted at correct places.
For this purpose you will have to use keydown function.




$(this).val().length gets the length of string typed.



Read More