The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Inserting the same code for use as a block of elements

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #44592

    I have an “Add” button that will add a group of fields to a list/form using JQuery.
    What’s the best way to do this?

    Do you set up a hidden group on the page and use Jquery to clone() it, append to the list, and then remove the class that is hiding it?

    Or do you code this group of content in Javascript somehow and build it each time you want to add a new group to the page?


    Use this as a little reference:

    I took a snippet from this site and basically hide the first element and copied the rest.


    Personally I would build the whole thing in JS. I sort of like John’s implementation with a ‘prototype’ node, and it seems to do a better job of separating markup and script… but it still feels hacky to me and it’s weird to have markup for content that shouldn’t be there yet.


    Ya know what, that is a good call. Build the elements with js, cache em, and duplicate. Afterwards set element attributes.

    , do you have some markup we could look at? Crocodillons implementation wouldn’t be hard at all.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.