What is jQuery ?

It’s very simple but most valuable Question on jQuery means jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, animating, event handling, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. jQuery is build library for javascript no need to write your own functions or script jQuery all ready done for you

Change the URL for a Hyperlink using jQuery

There are three way to change   the URL for a Hyperlink using jQuery.

1-   $("a").attr("href", "http://www.phpinterviewquestion.com/");

2- $("a[href='http://www.phpinterviewquestion.com/']")
     .attr('href',   'http://phpinterviewquestion.com/');
3-  $("a[href^='http://phpinterviewquestion.com']").each(function(){
      this.href = this.href.replace(/^http:\/\/beta\.phpinterviewquestion\.com/,
 "http://phpinterviewquestion.com");
     });

Check or Uncheck All Checkboxes using jquery

There  are different methods to check and uncheck the check boxes.

suppose that you have checkboxes like that

<input type=”checkbox”  value=”1″ name=”Items”  id=”Items1″ />
<input type=”checkbox”  value=”2″ name=”Items”  id=”Items2″ />
<input type=”checkbox”  value=”3″ name=”Items”  id=”Items3″ />
<input type=”checkbox”  value=”1″ name=”Items”  id=”Items4″ />

1- using attr() function.
$(‘#checkall’).click(function(){
$(“input[@name=’Items’]:checked”).attr(‘checked’,true);
});
$(‘#uncheckall’).click(function(){
$(“input[@name=’Items’]:checked”).attr(‘checked’,false);});

2- using attr() and removeAttr()funstions
$(‘#checkall’).click(function(){
$(“input[@name=’Items’]:checked”).attr(‘checked’,true);
})
$(‘#uncheckall’).click(function(){
$(“input[@name=’Items’]:checked”).removeAttr(‘checked’);})

Note- if your checkbox name is array type, then simple replace Items to Items[]

Fetch the values of selected checkbox array using JQuery

Suppose that below is checkbox array
<input type=”checkbox”  value=”1″ name=”Items[]”  id=”Items1″ />
<input type=”checkbox”  value=”2″ name=”Items[]”  id=”Items2″ />
<input type=”checkbox”  value=”3″ name=”Items[]”  id=”Items3″ />
<input type=”checkbox”  value=”1″ name=”Items[]”  id=”Items4″ />

and we want the get the value of selected checkbox using jquery.

then simple use below code.
var selItems = new Array();
$(input[@name=’Items[]’]:checked”).each(function() {selItems .push($(this).val());});

Here selItems will take all selected value of checkbox.

Page 1 of 3123
eXTReMe Tracker