jQuery Interview Questions and Answers (185) - Page 7

How to get or set element width in the Jquery whta is the method used ?

NOTE: This is objective type question, Please click question title for correct answer.
How to insert an element after a specific element ?

NOTE: This is objective type question, Please click question title for correct answer.
How to insert an element before a specific element ?

NOTE: This is objective type question, Please click question title for correct answer.
How do we retrive position of html in jquery ?

NOTE: This is objective type question, Please click question title for correct answer.
How to attach hover event to an element in Jquery ?

Here in the script in coding we have to attach or we have to use hover()method to hover event to a html element in jquery.
example:


<script type="text/javascript">
$("#pHover").hover(function () { $(this).hide(500); });
</script>


This function runs and shows the output as "when user mouse over “pHover”(pHover means div id name) element,it will hide."
How to attach keydown event to an element in jquery?

Here in the script in coding we have to attach or we have to use keydown() method to keydown event to show the html element in jquery.
example:

<script type="text/javascript">

$("#txtKeyPress").keydown(function () { $("#div3").append(" | key DOWN event fired"); });

</script>


when user press any key in the “txtKeyPress” textbox, “ | key DOWN event fired” text will appended in the “div3” element from the above code
How to attach keypress event to an element in jquery ?

In jquery keypress() method can be used to attach keypress event to a html element.

Example :
<script type="text/javascript">

$("#txtKeyPress").keypress(function () { $("#div3").append(" | key PRESS event fired"); });
</script>

From the code when user press the key in the “txtKeyPress” textbox, “ | key PRESS event fired” text will be appended in the “div3” element.
In jquery how to attach key up event to an element?

Here in the script in coding we have to attach or we have to use keyup() method to key up event to a html element
Example:
<script type="text/javascript">

$("#txtKeyPress").keyup(function () { $("#div3").append(" | key UP event fired"); });
</script>


when user leave then key in the “txtKeyPress” textbox then “ | key UP event fired” will be appended in the “div3” element.
How to attach load event to an element in jquery ?

in the script type we have to attach load method to an html element, load() method is used for the load function
Example:
<script type="text/javascript">

<img id="imgLoad" src="http://www.itfunda.com/Images/itfunda.gif" />
$("#imgLoad").load(function () {
alert("ITFunda.Com Logo loaded");
});
</script>

when the image will be loaded completely then user will be alerted from the above example
How to attach mouse down event to an element in jquery ?

mousedown() method can be used for mouse down event to a html element,.
Example :
<script type="text/javascript">


$("#spanMouseDownUp").mousedown(function () {
$(this).html("Mouse down");
});
</script>
<div id="spanMouseDownUp" style="background:green;
color:White;padding:10px;">Try to click here</div>


In mouse event method () when user start clicking mouse on the “spanMouserDownUp” element “Mouser clicked” will be written inside it.
How to attach mouse enter event to an element in jquery ?

To attach mouse enter event to a html element, mouseenter() method can be used.

$("#spanMouseDownUp").mouseenter(function () {
$(this).html("Mouse entered in this area");
});
<div id="spanMouseDownUp" style="background:green;color:White;padding:10px;">Try to bring your mouse here</div>


code mouse enter shows when user try to enter into the area of “spanMouseDownUp” element then “Mouse entered in this area” will be written inside it.
How to attach mouse leave event to an element?

in script coding we have to attach or we have to use mouseleave() method
Example :
<script type="text/javascript">


$("#spanMouseDownUp").mouseleave(function () {
$(this).html("Mouse left this area");
});
</script>
<div id="spanMouseDownUp" style="background:green;color:White;padding:10px;">Try to bring your mouse here</div>


Here when user try to leave the mouse from the “spanMouseDownUp” element then “Mouse left this area” text will be written inside it.
How to attach mouse move event to an element ?

mousemove() method is used in jquery to write mouse move elelment in the html.
Example
<script type="text/javascript"> 

$("#spanMouseDownUp").mousemove(function () {
$(this).html("You have started moving");
});
</script>
<div id="spanMouseDownUp" style="background:green;color:White;padding:10px;">Try to bring your mouse here</div>

In the code when user move mouse over “spanMouseDownUp” element then “You have started moving” text will be written inside it.
How to attach mouse up event to an element?

Here in the script in coding we have to attach or we have to use spanMouseDownUp to show the html element in jquery.
example:

<script type="text/javascript">

$("#spanMouseDownUp").mouseup(function () {
$(this).html("Mouse released");
});
</script>


In the above code when user releases the mouse button from “spanMouseDownUp” element then “Mouse released” text will be written inside it.
How to add a paragraph with Text says "Dotnetfunda.com" after every paragraph extracted by the selector paragraph?

We have a jQuery append method which appends Paragraphs.
Write below jQuery code:-
$("p").append("<p>Dotnetfunda.com</p>");

How to retrieve the Number of Rows in a Gridview through jQuery?

Write below code:-
var grid_row_count = $('#grid_view_id tr').length;

Because Gridview is internally rendered in Html table.
How to retrieve the Number of Rows in a HTML Table through jQuery?

Write below code:-
var table_row_count = $('#html_table_id tr').length;

For Example:-
Suppose,i have an HTML table which contains 4 <tr> i.e. rows as below:-
<table id = "html_table_id" style = "border-color:yellow;">   

<tr><td>DOT NET FUNDA.COM ROW1</td></tr>
<tr><td>DOT NET FUNDA.COM ROW2</td></tr>
<tr><td>DOT NET FUNDA.COM ROW3</td></tr>
<tr><td>DOT NET FUNDA.COM ROW4</td></tr>
</table>

Which statement is/are true about jQuery Selectors?

NOTE: This is objective type question, Please click question title for correct answer.
Which is the correct way to get Controls object in jQuery?

NOTE: This is objective type question, Please click question title for correct answer.
How to Add class to our controls dynamically?

addClass is an in-built jQuery method,which is used for adding class dynamically.We have to pass class name in this addClass method.
Syntax:-
addClass(our_className);

For Example:-
<script src = "//code.jquery.com/jquery-1.10.2.js"></script>

$("p").addClass("our_className");

Now,write your own class,and replace with our_className.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories