ineffable p
ineffable p

Reputation: 1189

Bootstrap Button dynamically through Jquery

I need to add button dynamically to the div , the button value is retrieved from var data = ev.dataTransfer.getData("Text");

So , Please suggest me the solution

<div class="span12" id="btndiv" ondrop="drop(event)" ondragover="allowDrop(event)"></div>

function drop(ev) {
        ev.preventDefault();
        var data = ev.dataTransfer.getData("Text");
   // Add Button here to div -btndiv

 <button class="btn btn-danger" data-jqui-type="" name="" type="submit"><i class="icon-close icon-white"></i> **data**</button>
    }

Upvotes: 0

Views: 2210

Answers (2)

adeneo
adeneo

Reputation: 318182

function drop(ev) {
    ev.preventDefault();
    var data = ev.dataTransfer.getData("Text"),
        btn  = $('<button />', {'class':'btn btn-danger', 
                                 text: data,
                                 name: '',
                                 type: 'submit',
                                'data-jqui-type':''
                               }),
          i  = $('<i />', {'class':'icon-close icon-white'});

    $('#btndiv').append(btn.prepend(i));
}

Upvotes: 0

tymeJV
tymeJV

Reputation: 104775

You can do:

$("<input/>").attr({type: "button", value: data}).appendTo("#btndiv");

Upvotes: 1

Related Questions