0

I'm trying to create a jQuery function to clone and append a text-field and select-box into the bottom of a div, like this:

$(".inline-form .copyIng:first-child").clone().appendTo(".inline-form");
$(".copyIng").trigger("create");

See this: http://jsfiddle.net/rxwL6/

But the 2 elements get's cloned twice and looks wired, any ideas why this happens?

Greeting :)

I'm sorry for answering my own question

, but the solution looks like this:

$(document).ready(function(){
  $("#newIng").click(function(){
  $(".inline-form .copyIng:first-child").clone().appendTo(".inline-form");
  });

  $("#newOve").click(function(){
    $('<div class="ove"><input type="text" name="c[]" class="field" placeholder="Overskrift"></div>').appendTo(".inline-form");
    $(".field").textinput();
  });
});
Sims
  • 167
  • 1
  • 1
  • 8

1 Answers1

0

Seems like you should use refrash event. The create event is suited for enhancing raw markup that contains one or more widgets. The refresh method should be used on existing (already enhanced) widgets that have been manipulated programmatically and need the UI be updated to match.

jsFiddle: http://jsfiddle.net/rxwL6/5/

YD1m
  • 5,845
  • 2
  • 19
  • 23