Category: JQuery

change the URL for a Hyperlink using jQuery

August 5, 2010 | Filed Under JQuery | Leave a Comment
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");
   });

Article written by admin

Check or Uncheck All Checkboxes using jquery

August 4, 2010 | Filed Under JQuery | Leave a Comment

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[]

Article written by admin

fetch the values of selected checkbox array using JQuery

August 4, 2010 | Filed Under JQuery | Leave a Comment

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.

Article written by admin

How we can apply css in multiple Selectors in jquery.

January 20, 2010 | Filed Under JQuery | Leave a Comment

Here is example to demonstrate

$(”div,span,p.myClass”).css(”border”,”1px solid green”);

the border will be apply in all div,span ,p.myClass class element.

Article written by admin

How we can modify the css class in jquery.

January 20, 2010 | Filed Under JQuery | Leave a Comment

Using css method we can modify class using jquery

example:$(”.CssClass1.CssClass2″).css(”border”,”1px solid green”);

CssClass1,CssClass2 will be modify to border 1px solid green.

Article written by admin

How can we apply css in div using jquery.

January 20, 2010 | Filed Under JQuery | Leave a Comment

using css() method we can apply css in div element.
example:
$(”div”).css(”border”,”1px solid green”);

Article written by admin

get the value of selected option in jquery

January 20, 2010 | Filed Under JQuery | Leave a Comment

suppose that below is the  selectbox/combobox

<select id="sel">
   <option value="1">Hi</option>
   <option value="2">Hello</option>
   <option value="3">Helloooooo</option>
   <option value="4">ok</option>
   <option value="5">Okey</option>
 </select>

want to get  the  value of selected option, then use
 $("select#sel").val();

or get the text of selected box, then use
$("#seloption:selected").text();

Example
Article written by admin

check/uncheck an input in jquery?

January 20, 2010 | Filed Under JQuery | Leave a Comment

Using two function, we can perform the operation.

// Check #x
$(”#checkboxid”).attr(”checked”, “checked”);
// Uncheck #x
$(”#checkboxid”).removeAttr(”checked”);

Example

Article written by admin

disable/enable an element in jquery?

January 20, 2010 | Filed Under JQuery | Leave a Comment

you can disable/enable web element using attr and removeAttr functions respectively

// Disable #x
$(”#x”).attr(”disabled”,”disabled”);
// Enable #x
$(”#x”).removeAttr(”disabled”);

Example:

Article written by admin

How do I determine the state of a toggled element?

January 20, 2010 | Filed Under JQuery | Leave a Comment

Here is the example of toggled element using the :visible or :hidden selectors.

var vis = $(’#formdiv’).is(’:visible’);
var hide= $(’#formdiv’).is(’:hidden’);
If you want to show a div visibility, then there is example for this
For example:

$(’#formdiv:visible’).animate({left: ‘+=100px’}, ’slow’);

Article written by admin

© PHPInterviewQuestion.com 2009 - 2010

eXTReMe Tracker