1

I was having a problem on calling bootstrap modal on a simple button or link maybe because its having a conflict with my select2 plugin (which I'm not really sure of) ,by the way I did just append the button to the select2 drop down, here is my javascript that wont work:

 $(".select2-drop").append('<table><tr><td><button class="btn" data-toggle="modal" data-target="#ModalAdd">New Supplier</button></td></tr></table>');`

because of this I'm just trying to do a javascript/jquery function to open the modal ( dont know if its the best way.)

here is my javascript code:

$(".select2-drop").append('<table><tr><td><button class="btn" onClick="modal() ">New Supplier</button></td></tr></table>');

tried to alert some message on it and it worked:

function modal(){
   alert("pressed");
}

My question is, How can I call modal on bootstrap via javascript/jquery function?

any kind of help/suggestions would really be appreciated, Thank you and have a good Day!

2 Answers 2

3

Try this

$('#modalID').modal('show')

By HTML

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#yourmodalid">
    Launch modal
</button>
Sign up to request clarification or add additional context in comments.

2 Comments

the second one wont work on me, as I said above it maybe have any conflict with my select2 :)
yeah, the second one works if I put the button outside the dropdown box, but when I try to append it on my select2's dropdown using jquerys append, I dont know but Its not working anymore!
1

If you want it completely "mechanical" see this example :

fiddle -> http://jsfiddle.net/RvJV8/

$("#btnOpen").click(function() {
    $("#myModal").modal();
});

Did you ever tried this? It works ..

$(".select2-drop").append('<table><tr><td><button class="btn" onclick="$(&quot;#myModal&quot;).modal();">New Supplier</button></td></tr></table>');

forked fiddle -> http://jsfiddle.net/3uZAZ/

2 Comments

thank you for your answer @davidkonrad, I really appreciate it, but I just dont know why its not working, and the only thing thats working on me is when I add the onClick property on the element and specifying it to a function. Im really confused why its happening, but anyways as long as its working I will be fine with it :)
@melvnberd, know this is closed but see update (just for demonstrating). You dont have to call an extra function, just place the code in your onclick-handler. BTW, the correct syntax is onclick, not onClick (it will fail in a HTML-validator)

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.