Friday 6 February 2015

38 TOP PHP and JQuery Interview Questions and Answers

1. What is jQuery ? | PHP and jQuery Questions
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

2. Change the URL for a Hyperlink using jQuery. | PHP and jQuery Questions
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");
     });

3. Check or Uncheck All Checkboxes using jquery. | PHP and jQuery Questions
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’);})

4. fetch the values of selected checkbox array using JQuery. | PHP and jQuery Questions
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.

5. How we can apply css in multiple Selectors in jquery. | PHP and jQuery Questions
Here  to take effect 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.

6. How we can modify the css class in jquery. | PHP and jQuery Questions
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.

7. How can we apply css in div using jquery. | PHP and jQuery Questions
using css() method we can apply css in div element.
example:
$(“div”).css(“border”,”1px solid green”);

8. get the value of selected option in jquery. | PHP and jQuery Questions
<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 text of selected box, then use
$("#seloption:selected").text();

9. check/uncheck an input in jquery? | PHP and jQuery Questions
Using two function, we can perform the operation.
// Check #x
$(“#checkboxid”).attr(“checked”, “checked”);
// Uncheck #x
$(“#checkboxid”).removeAttr(“checked”);

10. disable/enable an element in jquery? | PHP and jQuery Questions
// Disable #x
$(“#x”).attr(“disabled”,”disabled”);
// Enable #x
$(“#x”).removeAttr(“disabled”);
More Questions & Answers :-
Page1  Page2  Page3  Part4

No comments:

Post a Comment