How to answer the jquery question in the interview?

Source: Internet
Author: User

For the front-end newcomer, jquery was the interviewrelevant technical questions and answers are certainly essential, today and everyone to share isjquery Learning The common face questions and answers, hope that through the sharing of this article, can help new people better through the interview, a look at it. 1.jQueryin the library$() What is it? (The answer is as follows) $()function isjQuery ()a nickname for a function, at first glance it's weird, and it makesJQueryThe code is obscure and difficult to understand. Once you get used to it, you'll love the simplicity of it. $()function is used to wrap any object into aJQueryobject, and then you are allowed to invoke the definedJQueryseveral different methods on the object. You can even pass in a selector string$() function, it returns a containing all matchingDOMelement Array.JQueryobject. I have seen this question several times, and although it is very basic, it is often used to differentiate whether a developer understandsJQuery. 2.the page has5aelement, how to useJqueryto choose them? (answer)Another importantJquerythe problem is based on the selector. JQuerysupports different types of selectors, such asIDSelector,classSelector, Tag Selector. Given the fact that this question is not mentionedIDand theclass, you can use the tag Selector to select allDivelement. JQueryCode:$ ("div"), which returns a containing all5aDivLabel'sJQueryobject. For more detailed answers, refer to the article linked above. 3.jQueryin theIDselector andclassWhat is the difference between selectors? (answer)If you've ever usedCss, you might have knownIDselector andclassthe difference between selectors,JQueryThe same is true. IDSelector usesIDto select elements, such as#element1, whileclassSelector usesCSS classto select an element. When you only need to select an element, use theIDselector, and if you want to select a group with the sameCSS classelements, you need to useclassThe selector. During the interview process, you have a great chance of being asked to useIDselector andclassselector to write code. The followingJQuerycode uses theIDselector andclassselector: $ (' #LoginTextBox ')//Returns element wrapped as JQuery object with id= ' Logintextbox ' $ ('. Active ')//Returns all elements with CSS class active.This is an event handling issue. Jqueryprovides good support for events such as button clicks. You can use the following code to hide aIDorclassnavigate to the picture. You need to know how to set an event for a button and executeHide ()method, the code looks like this: As you can see, from a grammatical point of view,IDselector andclassAnother difference between selectors is that the former uses characters"#"while the latter uses characters".". For more detailed analysis and discussion, see the answer link above. 4.How to use when clicking on a buttonJQueryhide a picture? $ (' #ButtonToClick '). Click (function () { $ (' #ImageToHide '). Hide (); });I like the problem because it is very close to actual use and the code is not complicated. 5.$ (document). Ready ()what is a function? Why do you use it? (Answer)This question is very important and is often asked. Ready ()function is used to enter the document in the Readyexecutes code when the state is active. WhenDOMfully loaded (for exampleHTMLis fully parsedDOMTree When the build is complete),JQueryallows you to execute code. Use$ (document). Ready ()the best thing about it is that it works on all browsers,JQueryhelp you solve the cross-browser challenges. Users who need further information can clickAnswerlink to see a detailed discussion. 6.JavaScript window.onloadEvents andJQuery ReadyWhat is the difference between functions? (answer)this question and answer is immediately followed by the previous one. JavaScript window.onloadEvents andJQuery Readythe main difference between functions is that the former is not only waiting forDOMcreated to wait until all external resources, including large pictures, audio, and video, are fully loaded. If you spend a lot of time loading pictures and media content, users will feel defined inwindow.onloadThe code on the event has a noticeable delay in execution. On the other hand,JQuery Ready ()function only needs toDOMThe tree waits without waiting for the image or external resources to load, and thus executes faster. UseJQuery $ (document). Ready ()Another advantage is that you can use it more than once in a Web page, and the browser will press theHTMLexecute them in the order they appear in the page, insteadonloadTechnically, it can only be used in a single function. Given this benefit, useJQuery Ready ()function Comparison withJavaScript window.onloadThe events are better. 7.how to find allHTML Selectthe selected item of the label? (The answer is as follows)It's a tricky interview .Jqueryone of the problems. It's a basic problem, but don't expect everyJQueryBeginners all know it. Can you use the followingJQueryselector gets allmultiple=trueof theFile:///c:\users\wlc\appdata\local\temp\ksohtml\wps6d99.tmp.png $ (' [Name=nameofselectedtag]: Selected ')This code combines the use of a property selector and: Selectedselector, the result returns only the selected option. You can modify it as needed, such as withIDproperty rather thannameproperty to getFile:///c:\users\wlc\appdata\local\temp\ksohtml\wps6dc9.tmp.png 8.jQueryin theEach ()what is the function? How do you use it? (The answer is as follows) each ()functions are likeJavaone of theIterator, which allows you to traverse a collection of elements. You can pass a function toEach ()method that is called by theJQueryObject executes the passed-in function on each of its elements. Sometimes this problem will be followed by a question, for example, how toAlertAll selected items are displayed in the box. We can use the selector code above to find all the selected items, and then weAlertBoxEach ()methods to print each of them, the code is as follows: $ (' [Name=nameofselectedtag]: Selected '). each (function (selected) { Alert ($ (selected). text ()); });whichText ()method returns the text of the option. 9.How do you put aHTMLelement is added to theDOMin the tree? (The answer is as follows)You can useJqueryMethodAppendTo ()will aHTMLelement is added to theDOMthe tree. This isJQueryMany of the controls providedDOMone of the methods. You can passAppendTo ()method in the specifiedDOMadd an existing element at the end of the element or a newHTMLelement. 10.You can useJQuerydoes the code select all the hyperlinks inside the paragraph? (the answer is slightly)Here's another one about selectors.Jqueryface questions. Just like any other problem, just one lineJQuerycode to get it done. You can use the followingJQuerycode snippet to select all nested in the paragraph (tags) Internal hyperlinks (tags)...... 11.$ (This)and the Thiskeyword inJQueryWhat's the difference? (The answer is as follows)This is for manyJqueryBeginners is a tricky problem, in fact, is a simple question. $ (This)returns aJQueryobject, you can call multipleJQuerymethods, such as usingtext ()get the text, usingVal ()get the value and so on. and Thisrepresents the current element, which isJavaScriptOne of the keywords that represents the current in the contextDOMelement. You can't call it on itJQuerymethod until it is$() function packages, such as$ (This). 12.How do you useJQueryto extract aHTMLthe attributes of the tag, such as. linked tohref? (Answer) attr ()method is used to extract anyHTMLthe value of an attribute of an element. you first need to useJQuerySelect and choose to all links or a specific link, and then you can applyattr ()methods to get theirhrefthe value of the property. The following code finds all the links in the page and returnshrefvalues: $ (' a '). each (function () { Alert ($ (this). attr (' href ')); }); 13.How do you useJQueryset a property value? (Answer)one additional follow-up question after the previous question is,attr ()Methods andJQueryother methods in the same way, the ability is more than the same. If you are callingattr ()with a value such as. attr (name, value),herenameis the name of the property,valueis the new value of the property. 14.jQueryinDetach ()and theRemove ()What is the difference between methods? (Answer)despiteDetach ()and theRemove ()method is used to remove aDOMElements, The main difference between the two is thatDetach ()keeps track of the elements that were removed from the past., so it can be lifted off, andRemove ()method keeps a reference to the object that was removed in the past. You can also look at theDOMelement is added in theAppendTo ()Method. 15.How do you useJQueryto add to and remove from an elementCSSclass? (Answer)by usingAddClass ()and theremoveclass ()of these twoJQuerymethod. Dynamic changes in the elementsclassproperties can be very simple for example. using Classes". Active"to mark their inactive and active states, and so on .. 16.UseCDNLoadingJQueryWhat are the main advantages of the library?? (Answer)It's a little bit more advanced.Jqueryproblem. Well, in addition to the many benefits of saving server bandwidth and faster download speed with an error, Most importantly, if the browser is already from the sameCDNDownload the same classJQueryversion, then it's not going to download it again.. so today, many public websites willJQueryfor user interaction and animations, If the browser already has the download goodJQueryLibrary, the site will have a very good opportunity to display. Jquery.get ()and theJquery.ajax ()What is the difference between methods? Ajax ()method is more powerful and more configurable, allows you to specify how long to wait and how to handle errors. get ()method is a specialized method that only gets some data. 18.jQuerywhat is the method chain in? What are the benefits of using a method chain? The method chain is to call another method on the result returned by one method, which makes the code simple and straightforward, and because only theDomperform a round of lookups, and perform better in terms of performance. 19.If you were in aJQuerythe event handler returnsfalseWhat will happen? This is typically used to prevent events from bubbling up. 20.which way is more efficient:document.getElementById ("MyId")or is$ ("#myId")? first, because it calls directly theJavascriptengine. Article source: Bo see Evans

How to answer the jquery question in the interview?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.