There are three way tochange 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"); });
change the URL for a Hyperlink using jQuery
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.
How we can apply css in multiple Selectors in jquery.
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.
How we can modify the css class in jquery.
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.
How can we apply css in div using jquery.
using css() method we can apply css in div element.
example:
$(”div”).css(”border”,”1px solid green”);
get the value of selected option in jquery
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
check/uncheck an input in jquery?
Using two function, we can perform the operation.
// Check #x
$(”#checkboxid”).attr(”checked”, “checked”);
// Uncheck #x
$(”#checkboxid”).removeAttr(”checked”);
Example
disable/enable an element in jquery?
you can disable/enable web element using attr and removeAttr functions respectively
// Disable #x
$(”#x”).attr(”disabled”,”disabled”);
// Enable #x
$(”#x”).removeAttr(”disabled”);
Example:
How do I determine the state of a toggled element?
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’);

