Big News: FounderDating is joining OneVest to build the largest community for entrepreneurs. Details here
Latest Notifications
You have no recent recommendations.
Name
Title
 
MiniBio
FOLLOW
Title
 Followers
FOLLOW TOPIC

Question goes here

1,300 Followers

  • Name
    Entrepreneur
  • Name
    Entrepreneur
  • Name
    Entrepreneur
  • Name
    Entrepreneur
  • Name
    Entrepreneur
  • Name
    Entrepreneur
  • Name
    Entrepreneur
  • Name
    Entrepreneur

Which is the correct or better way to create a new element with jQuery?

I consider myself a rookie when it comes down to programming. Thanks a lot for the thoughtful responses in advance.

3 Replies

Alexander Conroy
0
0
Alexander Conroy Entrepreneur
Programmer, Developer, Digital Marketer, Entrepreneur, Speaker, Wearables
I prefer var element = $('<element>'). It will create the element then you can just

$('otherselector').append(element); You can also run anything you want on element before appending or prepending or whatever. Don't forget there are many different DOM insertion functions and you will have to choose where to insert!
Tom DiClemente
0
0
Tom DiClemente Advisor
Management Consulting | Interim CEO/COO | Coach
Go tohttps://learn.jquery.com/using-jquery-core/manipulating-elements/ and scroll down to creating new elements.
Brandon S
0
1
Brandon S Entrepreneur
UX Designer at REC1 Software
Well, we're talking about creating an element, not appending elements into other elements. If you want to actually create an element in javascript or jQuery, you would use the following syntax:

e.g. if you want to create a button with merely javascript

var btn = document.createElement("BUTTON");

e.g. if you want to then append that element or add this element to the DOM (page), you would use the following syntax:

document.body.appendChild(btn);

e.g. If you want to create a button in jQuery and then append that button to the DOM (page), you would use the following syntax:

var t = $("<button></button>");
$('body').append(t);
Join FounderDating to participate in the discussion
Nothing gets posted to LinkedIn and your information will not be shared.

Just a few more details please.

DO: Start a discussion, share a resource, or ask a question related to entrepreneurship.
DON'T: Post about prohibited topics such as recruiting, cofounder wanted, check out my product
or feedback on the FD site (you can send this to us directly info@founderdating.com).
See the Community Code of Conduct for more details.

Title

Give your question or discussion topic a great title, make it catchy and succinct.

Details

Make sure what you're about to say is specific and relevant - you'll get better responses.

Topics

Tag your discussion so you get more relevant responses.

Question goes here

1,300 Followers

  • Name
    Details
  • Name
    Details
  • Name
    Details
  • Name
    Details
  • Name
    Details
  • Name
    Details
  • Name
    Details
  • Name
    Details
Know someone who should answer this question? Enter their email below
Stay current and follow these discussion topics?