I am not familiar with the below syntax. What is the purpose of adding the object?
selectIt = $('<div />', {text : $this.attr('title')});
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code in your question body creates a
divnode, settingstext(i.e. its inner HTML) to the value of$this.attr('title'). The div node will be assigned to theselectItvariable, but is not yet appended to any part of the DOM.The code in your question title is also valid, except for the unclosed string. It selects the element with the id
myID, searching only within the DOM nodeobj. Passing a context node is superfluous when selecting by ID, seeing as ID’s are unique in the document, and selecting by ID is quick enough, but for other elements, it can be a useful way to add precision, and not have to search the entire document.Note the difference between passing a bit of HTML, which will instruct jQuery to create the matching node tree, so that you may append it to the DOM, or passing a selector, which will instruct jQuery to find the matching nodes within the current DOM.