0

I have the following href link

<a href="{$data.base_url}find_dates.html"  data-toggle="modal" style="color:#fff;" class="modal-ajax">Click Here to View data</a>

and the pop is showing on page reload, but I want to show it only on click.

$('.modal-ajax').modal();

Now the page is redirect into url. I want to show the pop up

I didnt wrote any js code. i tried this now

$('a').click( function(e) {
    e.preventDefault(); 
    $('.modal-ajax').modal();
    return true; 
} );

but it raises $('.modal-ajax').modal(); is not a function error

  • Possible duplicate of [How to open a Bootstrap modal window using jQuery?](https://stackoverflow.com/questions/13183630/how-to-open-a-bootstrap-modal-window-using-jquery) – Masoud Keshavarz Aug 26 '19 at 06:15
  • No. its differnt. it was working before but now something happened... i didnt wrote any javascript cod – Sherin Reynold Aug 26 '19 at 06:19
  • you want to open modal on anchor click , So you need to use ID or class of the Modal i.e $("#modalID") or $(".ModalClass") .Try this way – Ricky Aug 26 '19 at 06:38

2 Answers2

0

Please try this

<a href="#" data-id="{$data.base_url}find_dates.html"  data-toggle="modal" style="color:#fff;" class="modal-ajax">Click Here to View data</a>


$('.modal-ajax').on('click', function() {
    var url = $(this).attr('data-id');
    //place this value wherever you want in modal.
    $('#openModal').show();
});
0

You could simply put a comment on the javascript code that trigger the modal :

// $('.modal-ajax').modal();

Then add a click event listener for the element you wish to be clicked :

$('a.modal-ajax').click(function(event) {
    event.preventDefault();
    $('.modal-ajax').modal();
});
Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26