Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  38] [ 4]  / answers: 1 / hits: 86094  / 9 Years ago, fri, may 22, 2015, 12:00:00

I have a modal which is open when i click on a button. Now i want to open the modal in a javascript function.
Here is the working modal :



<a href=# class=btn btn-lg btn-primary id=sentMessage data-toggle=modal data-target=#largeModal>Click to open Modal</a>
<div class=modal fade id=largeModal tabindex=-1 role=dialog aria-labelledby=largeModal aria-hidden=true>
<div class=modal-dialog modal-lg>
<div class=modal-content>
<div class=modal-header>
<button type=button class=close data-dismiss=modal aria-hidden=true>&times;</button>
<h4 class=modal-title id=myModalLabel>Large Modal</h4>
</div>
<div class=modal-body>
<h3>Modal Body</h3>
</div>
<div class=modal-footer>
<button type=button class=btn btn-default data-dismiss=modal>Close</button>
<button type=button class=btn btn-primary>Save changes</button>
</div>
</div>
</div>
</div>


I want to open the same modal in a javascript function. So to simulate this function, i create another button which trigger a function :



<a href=# ng-click=openModal(); class=btn btn-lg btn-primary>Click to execute js</a>


Here is my openModal function :



$scope.openModal = function(){
$(#sentMessage).click();

};


When i click on the button Click to execute js, the modal does not open.
Here is the plunker


More From » jquery

 Answers
67

you can use the modal function:



$('#largeModal').modal('show');

[#66500] Wednesday, May 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
george

Total Points: 2
Total Questions: 98
Total Answers: 105

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
;