Home
Jquery
Interview FAQs

FAQs of level

The mouseenter event occurs when the mouse pointer enters into the specified HTML element. For example, a paragraph, div elements of HTML. The jQuery mouseenter method is used to perform the desired action as mouseenter event takes place. mouseenter is generally used with the mouseleave event.
Following is the syntax of mouse enter method:
$(selector).mouseenter(function)
Where a function in jQuery mouseneter method is optional. It runs as the mouseenter event occurs.
e.g.
$("p"). mouseenter(function)
$("div"). mouseenter(function)
$("button"). mouseenter(function)

As working with jQuery in your web pages for different elements, it becomes quite useful if CSS can be applied or changed dynamically for different elements. For example, showing an element by using jQuery .show method and changing its CSS.Similarly, new elements added dynamically by using jQuery and you want to apply CSS by using jQuery as well. An element made hidden by using display: none property of CSS in the stylesheet and you want to make it visible and so on.jQuery comes up with $.css method that can be used to change/apply CSS to specified element(s) as well as return style properties for the given elements.
Syntax of using jQuery CSS method
selector.css(“css_property”,”property_value”);
You can also apply multiple CSS properties by using the following syntax:
selector.css({“css_property”:”property_value”, “css_property”:”property_value”,……})
Where,

  • the selector can be an element like a paragraph, div etc.
  • .css is jQuery method name to apply/change CSS of the specified element.
  • For the single property, you can simply enclose CSS property in double quotes followed by the property value.
e.g. CSS property name = “color” and value = “red”
  • For setting multiple CSS properties, enclose properties into the curly brackets. Each property is separated by a comma.
e.g. p.css({“color”:”red”, “font-size”:”12px”});

You can use $.html method of jQuery to get the content of specified elements. The method will return only first matched elements content if there are multiple occurrences.

For example, if you have two or three paragraphs with text information, calling html method will return only first paragraphs content.
Syntax to get content:
$(“element”).html()
Note that, this will return HTML code, not the formatted text. 

You can use $.html method to set or add HTML content to the specified elements. Unlike using the HTML method to get content, setting HTML will affect all matched elements.
Note that, the content will be replaced for all matched elements.
Syntax to set content
$(“element”).html(“HTML_Content”);
For example, if you have two paragraphs and you set the content by $.html method, it will replace the given content with existing content. 

In many scenarios, you may need to add content, some plain text, HTML text or other elements to your web page without reloading.jQuery makes it quite easier by way of few methods that allow to add content in the web pages. The placement of content can also be controlled easily, depending on jQuery method you are using to add content.
Methods to add content
Following are methods supported in jQuery to add content:
1- $.append
The append method adds content to the end of a given element.
For example:p.append("content") will add content to the end of paragraphs in the document.
2- $.prepend
The prepend method, as opposed to append method, adds content at the beginning of the specified element. 
For example:p.append("content") will add content at the beginning of paragraphs in the document.

The syntax of append() method is-
selector.append(“content to be added”);
Where selector can be an element where you want to add content. 

In many scenarios, you may need to add content, some plain text, HTML text or other elements to your web page without reloading.jQuery makes it quite easier by way of few methods that allow to add content in the web pages. The placement of content can also be controlled easily, depending on jQuery method you are using to add content. In the example below, we will show you how to add simple text at the end of a paragraph. As you click on the button "Add content", it will add given plain text attached to the click event of the button to end of the paragraph.

<html> 
<head>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script> 
$(document).ready(function(){ 
  $("#addcontent").click(function(){ 
    $("#content").append(" Add content! "); 
  }); 
});
 </script> 
</head> 
<body> 
<button id="addcontent">Add content</button> 
<p id="content">Paragraph where content will insert! </p> 
</body> 
</html>

document.ready() function is different from body onload() function for 2 reasons.
1. We can have more than one document.ready() function in a page where we can have only one body onload function.
2. document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.

jQuery library comes in 2 different versions Production and Deployment. The deployment version is also known as minified version. So .min.js is basically the

minified version of jQuery library file. Both the files are same as far as functionality is concerned. But .min.js is quite small in size so it loads quickly and saves bandwidth.

jQuery library comes in 2 different versions.

1. Production

2. Deployment
The production version is quite useful at development time as jQuery is open source and if you want to change something then you can make those changes in production version. But the deployment version is minified version or compressed version so it is impossible to make changes in it. Because it is compressed, so its size is very less than the production version which affects the page load time.

PreviousDisplaying 2 of 7Next
1 2 3 4 5 6 7
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*