Add Div Dynamically using JQuery

后端 未结 5 682
庸人自扰
庸人自扰 2021-02-13 09:54

I\'m not sure if this would be the best option.. But I want the option that when the user clicks a button, it will add another div or li.

I am going to allow users to u

相关标签:
5条回答
  • 2021-02-13 10:13

    If this is to allow for multiple file uploads, have you considered using something like http://www.uploadify.com/ the jQuery plugin? It allows multiple file uploads from one dialog window and you wouldn't need to worry about this.

    0 讨论(0)
  • 2021-02-13 10:13

    Your example updated on jsFiddle

    $("input[type=submit]").click(function(){
        $("<li />").html("item").appendTo("ul");
    })
    

    You can create elements using $("<tag />") and set attributes, add classes and so on. Then append where you want.

    0 讨论(0)
  • 2021-02-13 10:17

    Try this:

    $('.button').click(function() {
        $('#myContainer').append('<div>the new guy</div>');
    });
    
    0 讨论(0)
  • 2021-02-13 10:19
    $("input[type=submit]").click(function(){
        $("<li />").html("item").appendTo("ul");
    })
    

    You can create elements using $("<tag />") and set attributes, add classes and so on. Then append where you want.

    0 讨论(0)
  • 2021-02-13 10:26

    You can add a new element to an existing parent like so:

    select the element to added the new <div>/<li> to and use .append()

    $("#id").append("<div>foo</div>");
    

    http://api.jquery.com/append/

    Alternatively, you can use the .html()

    http://api.jquery.com/html/

    0 讨论(0)
提交回复
热议问题