Ten jQuery code snippets help improve Web development efficiency, and ten jquery
JQuery is another excellent Javascript library after prototype. It is a lightweight js library, compatible with CSS3, and compatible with various browsers (IE 6.0 +, FF 1.5 +, Safari 2.0 +, and Opera 9.0 + ), jQuery2.0 and later versions will no longer support IE6/7/8 browsers. JQuery allows you to easily process HTML (an application in a standard General Markup Language), events, and animation effects, and provides AJAX interaction for websites. Another major advantage of jQuery is its comprehensive documentation and detailed description of various applications. There are also many mature plug-ins to choose from. JQuery can ensure that the user's html page is separated from the code and html content. That is to say, you do not need to insert a bunch of JavaScript code into the html to call the command. You only need to define the id. The following ten jQuery examples can help you smoothly improve the efficiency of Web design projects.
Check IE browser
When designing CSS, IE browser is undoubtedly troublesome for developers and designers. Although the Dark Age of Internet Explorer 6 has passed and the popularity of the Internet Explorer family is declining, we still need to detect it. Of course, the following snippets can also be used to detect other browsers.
Source: Stack Overflow
Scroll smoothly to the top of the page
The following is one of the most common implementations of jQuery: click a link to scroll smoothly to the top of the page. Although there is no freshness, almost every developer can use it.
Source: Stalk Overflow
Always on top
The following code snippet allows an element to always be at the top of the page. As you can see, it is very suitable for handling navigation menus, toolbar or other important information.
Source: DesignBump
Replacing html tags
JQuery can easily implement html tag replacement, which will bring us more new possibilities.
Source: Allure Web Solutions
Detect screen width
Nowadays, mobile devices are more popular than traditional computers, so it is very important to detect the size of small screens. Fortunately, we can use jQuery to easily implement this function.
Source: jQuery Rain
Automatic repair of damaged Images
If your website is very large and has been online for several years, images may be damaged more or less. This function can detect damaged images and replace them according to our selection.
Source: WebDesignerDepot
Check copy, paste and cut operations
With jQuery, you can easily detect the copy, paste, and cut operations of Selected elements.
Source: Snipplr
Automatically add target = "blank" attribute for external links
When connecting to an external site, you may want to use the target = "blank" attribute to make sure that the page is opened on a new tab. The problem is that the target = "blank" attribute has not been W3C certified. JQuery can be of great help: the following parts can detect whether the current link is directed to the outside, and if so, the target = "blank" attribute is automatically added for it.
Source: jQuery Rain
Fade in/out when hovering
This is another "classic" effect. You can use the following fragments at any time.
Source: Snipplr
Disable spaces in text/Password Input
No space is required for many common fields, such as email, user name, and password. The following code can easily disable all spaces in the selected input content.
Copyright statement: Title of the original article: 10 jQuery Snippets for Efficient Web Development, 51CTO translation. for details on the Cooperation site, please indicate the source and source of the original article: 51CTO.com, Translated by: 51CTO, thanks to the hard work of the original author. For copyright record-related issues, please contact us (Public Account: shutong changlian, QQ group: 299719834) and we will handle the issue immediately. Thank you!