Is there any reason I would use $('<div></div>') instead of $('<div>')?
Or $('<div><b></b></div>') instead of $('<div><b>')?
I like the latter in both cases because it is shorter.
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.
That depends on whether you use a single tag or multiple tags to create the element/elements.
If you use a single tag, jQuery will use the
document.createElementmethod to create the element, so it doesn’t matter if you use"<div/>"or"<div></div>".If you have several elements, jQuery will create the elements by creating a
divelement and put the HTML code in theinnerHTMLproperty. To get the browser to parse the HTML code properly, you have to write it according to the HTML version you are using. If you are using XHTML for the page, the HTML code that you use to create elements has to be XHTML also.