0

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>
    }
1
  • You want to add the button or just give the existing button a value? Commented Jul 16, 2013 at 16:19

2 Answers 2

1

You can do:

$("<input/>").attr({type: "button", value: data}).appendTo("#btndiv");
Sign up to request clarification or add additional context in comments.

2 Comments

How can I add CSS for this one
Add a class to this, and create a CSS class, example CSS class of test, then .attr({"class":"test"})
0
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));
}

3 Comments

i = $('<i />', {'class':'icon-close icon-white'} is not adding to the button
@ineffablep - It does add the icon, but there is no icon-close as far as I know. Changing the icon class makes it work -> jsfiddle.net/b4Dj5
Here are all the available icons and their names -> twitter.github.io/bootstrap/base-css.html#icons

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.