The below function takes array element which needs to be removed as parameter as below

01
02
03
04
05
06
07
08
09
10
11
12
ary.remove(‘One’);
var ary = [‘One’, ‘Two’, ‘Three’];
Array.prototype.remove = function() {
    var what, a = arguments, L = a.length, ax;
    while (L && this.length) {
        what = a[--L];
        while ((ax = this.indexOf(what)) !== -1) {
            this.splice(ax, 1);
        }
    }
    return this;
};

The above method works perfectly works for java script array with strings in it.

For the below variable

1
2
3
var csvEmpIds = ‘1,2,3,4,5’;
arrEmpIds = csvEmpIds.split(‘,’);
ary.remove(2);

The above will not work as you should pass 2 as a string and split function creates
a array by splitting from one variable and putting as a strings in array.

so csvEmpIds.split(‘,’) will create array like below

1
arrEmpIds = ['1','2','3','4','5'];

In this case to remove element from array which you got by splitting come delimited value you should
do as below.

1
ary.remove('2');

To Remove array which is declared globally use the below function

1
2
var ary = ['three', 'seven', 'eleven'];
removeA(ary, 'seven');
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
function removeA(arr)
{
  var what, a = arguments, L = a.length, ax;
   
  while (L > 1 && arr.length)
  {
    what = a[--L];
    while ((ax= arr.indexOf(what)) !== -1)
    {
      arr.splice(ax, 1);
    }
   }
 
   return arr;
}

HTTP Cookies are not a feature of PHP, nor a feature of Javascript : those are just programming languages that allow a developper to manipulate them.

The biggest difference between JS and PHP is that :

Javascript runs on the client side
PHP runs on the server side

But cookies are still the same : they are defined as a standard — see RFC 2965.

Still, note that modern browsers implement cookies that are not accessible from Javascript (see the httponly option of setcookie) — which means that, depending on the browser, and the way a cookie was set, it might not be accessible from Javascript.

This is a security measure — and is not a difference between “js cookies” and “php cookies” : it’s just a property of some cookies.

Create session cookie

  $.cookie('CookieName', 'Value');

Cookie that Expires in 7 days

 $.cookie('CookieName', 'Value', { expires: 7 });

Create cookie valid across entire site:

  $.cookie('CookieName', 'Value', { expires: 7, path: '/' });

Read value cookie:

 $.cookie('the_cookie'); // => "the_value"
 $.cookie('not_existing'); // => null

Delete cookie:

 // Returns true when cookie was found, false when no cookie was found...
 $.removeCookie('the_cookie');

 // Same path as when the cookie was written...
 $.removeCookie('the_cookie', { path: '/' });
//function for converting string into indian currency format
    function intToFormat(nStr)
    {
     nStr += '';
     x = nStr.split('.');
     x1 = x[0];
     x2 = x.length > 1 ? '.' + x[1] : '';
     var rgx = /(d+)(d{3})/;
     var z = 0;
     var len = String(x1).length;
     var num = parseInt((len/2)-1);
 
      while (rgx.test(x1))
      {
        if(z > 0)
        {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
        }
        else
        {
          x1 = x1.replace(rgx, '$1' + ',' + '$2');
          rgx = /(d+)(d{2})/;
        }
        z++;
        num--;
        if(num == 0)
        {
          break;
        }
      }
     return x1 + x2;
    }

In jQuery, suppose you have an element of some kind that you’re hiding and showing, using .hide(), .show() or .toggle(). How do you test to see if that element is currently hidden or visible on the screen?

 // Checks for display:[none|block], ignores visible:[true|false]
 $(element).is(":visible") 

You can use the “hidden” and “visible” selectors.

 $('element:hidden')
 $('element:visible')
01
02
03
04
05
06
07
08
09
10
<div class="pagination">              
  <span class="prev"></span>
  <span class="num" id="1">1</span>
  <span class="num_active" id="2">2</span>
  <span class="num" id="3">3</span>
  <span class="num" id="4">4</span>
  <span class="num" id="5">5</span>
  <span class="num" id="6">6</span>
  <span class="next"></span>
 </div>
1
2
3
4
5
6
$('.pagination span').click(function(){
$(".pagination span").removeClass("num_active").addClass("num");
$(".pagination span:first").removeClass("num").addClass('prev');
$(".pagination span:last").removeClass("num").addClass('next');
      $(this).addClass("num_active");
});

Javascript Code
Please Note – this doesnt work with old version of js File

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
$('document').ready(function(){
$('#cboCity').live("change", function(){
alert('Hi there');
});
 
$('#btnChange').on("click", function(){
changeCities();
});
});
 
function changeCities()
{
strSelect = "<select id='cboCity' name='cboCity'><option>Chennai</option><option>Mumbai</option></select>";
$('#City').html(strSelect);
}

HTML Code

01
02
03
04
05
06
07
08
09
10
11
12
13
14
<input id="btnChange" type="button" name="btnChange" value="Change Me" /></pre>
<table>
<tbody>
<tr>
<td>
<div id="City">
<select id="cboCity" name="cboCity"><option>Chennai</option><option>Mumbai</option><option>Delhi</option><option>Kolkatta</option><option>Andrapradesh</option>
</select>
 
</div>
</td>
</tr>
</tbody>
</table>