Forums

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

Home Forums JavaScript Dynamically generated input is getting overriding by previous input

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #148234
    leongaban
    Participant

    Hi :) so I have code here http://codepen.io/leongaban/pen/IAKEr

    It’s suppose to generate 2 labels & 2 input fields, however only 1 is displayed. I know this is because of this line: $('.new_option').append(inputphone); I’m not dynamically generating a new ul & class here.

    How would you go about doing this?

    #148239
    TheDoc
    Member

    Using a for loop seems to solve the issue, though I’m not entirely sure why.

    http://codepen.io/ggilmore/pen/f3a88dd68a7b1d101712b75318925198

    Notice that I’m also applying unique classnames to each of the list items as well.

    #148247
    leongaban
    Participant

    Thanks! Trying this out in my project now, perhaps I should have started with a normal for loop in the first place. I guess each should be reserved for counting elements already on the DOM…

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