Make modal appear on screen after creating

Asked

Viewed 47 times

0

$('a[rel=modal]').click( function(){
  var id = $(this).attr('href');
  var a1 = [];
  for (var i = 0; i < id.length; i++) {
    a1[i] = (id[i+1]);
  }
  var a2 = a1.join('');
  var idTime = parseInt(a2);


  modaisTime= $('#modaisTime');
  var t = JSON.parse(localStorage.getItem('Times'));
  modaisTime.html('');
  modaisTime.append('<div id="'+ idTime +'" class="modal modal-fixed-footer"><div class="modal-content"><h4 class="center-align">Time</h4><li class="divider1"></li><p class="flow-text col s12 m6">Nome: '+t[idTime].nome+'</p><p class="flow-text col s12 m6">CNPJ: '+t[idTime].c+'</p><p class="flow-text col s12 m6">Responsável: '+t[idTime].nomeR+'</p><p class="flow-text col s12 m6">CPF: '+t[idTime].cpfR+'</p></div><div class="modal-footer"><button id="editar" class="modal-action waves-effect waves-red btn-flat" type="button" onclick="editar('+idTime+')">Editar</button></div></div></div>');
  $(id).toggle();   
});
<div id="mostrarTimes">
  <h5 class="col s7">Flamengo</h5>
  <a href="#0" rel="modal"></a>
 </div>
 
 <div id="modaisTime">

The thing is, I wanted to do this already showing the modal with href, but I can’t, hold on would know how to do after the modal be created it open?

  • Which Modal are you wearing? Bootstrap?

  • @Localhost, that kind of improvements can hide the problem from the question, so it is better not to. If the problem is the lack of this > it will be difficult for anyone to discover since the question no longer reflects it.

  • @Sergio, oh yes, I understand. Shall I undo it then? It’s just that I thought he forgot at the time of the typing, just like the rest of the div, which seems to be missing...

  • @Localhost we leave until the AP appears here and explain the question better. The intention is clear! :)

  • Test this by using bootstrap: https://www.w3schools.com/bootstrap/bootstrap_ref_js_modal.asp

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.