Logo F2FInterview

jQuery Interview Questions

Q   |   QA

CDN - It stands for Content Distribution Network or Content Delivery Network.

Generally, a group of systems at various places connected to transfer data files between them to increase its bandwidth while accessing data. The typical architecture is designed in such a way that a client access a file copy from its nearest client rather than accessing it from a centralized server.

So we can load this jQuery file from that CDN so that the efficiency of all the clients working under that network will be increased.

Example :

We can load jQuery from Google libraries API

<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>

Yes, we can select an element with a specific class, we use the class selector.The class name must contain the prefix as "." (dot).

<script language="javascript" type="text/javascript">

         $(".class1").css("border", "2px solid red");

</script>

 

Above code will select all the elements of the webpage containing the class as "class1" and apply the css style border width as 2 Pixel, style as solid and color as red.

The delegate() method can be used in two ways.
1) If you have a parent element, and you want to attach an event to each one of its child elements, this delegate() method is used.
Ex:Un-ordered List
Instead of attaching an event to each <li> element, you can attach a single event to <ul> element.

Example:

$("ul").delegate("li", "click", function(){

$(this).hide();

});

 

2) When an element is not available on the current page, this method is used.
.live() method is also used for the same purpose but, delegate() method is a bit faster.

Example:

$("ul").delegate("li", "click", function(){

$(this).hide();

});

 

This will hide any list items that are not currently available on the page. They may be loaded via an Ajax request and then append to it.
Using .bind() or .click() methods, you would have to manually attach events to these new list items once they are added.

Let us consider a scenario, There are n number of fields with different ids.We need to get the value of all the fields dynamically without specifying id explicitly.

For Example, lets have following html tags in our html form:

<input type="text" id="id_1" value="rosary"/><br/>
<input type="text" id="id_2" value="prabhu"/><br/>
<input type="text" id="id_3" value="stephen"/><br/>
<input type="text" id="id_4" value="ilango"/><br/>
<input type="text" id="id_5" value="sathya"/><br/>

We need to get the values of each text box fields dynamically without specifying each ids explicitly.

Following is the code snippet to achieve the above task:

for (var i=1; i<=5; i++) {
var test = $("input[id='id_" + i + "']").val();
alert (test);
}

You can also achieve the same using following code snippet

$("input[type='text']").each(function(){
var test = $("input[id='"+this.id+"']").val();
});

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: