1
I make a call Ajax and this call returns some data. I need to pass a data of descrição, is a string with a text, but to pass this data in the modal I am using the data- and for this I need to convert to text. I am looking for a method to format this descricao within the modal. Removing the   and putting in place a <br>.
How the date is being made
var descricao = $(json[i].descricao).text(); //Converter para texto, pois ela vem com as tags html
<div class="card opModalGaleria" id="`+json[i].seq_membro_galeria+`" data-toggle="modal" data-target="#modalGaleria" data-descricao="`+descricao+`">
And then when it’s time to show off I can’t replace   for <br> to properly format in modal a descrição.
$('#modalGaleria').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var descricao = button.data('descricao')
var descricaoFormatada = descricao.replace(/ /g,"<br/>")
var modal = $(this)
modal.find('#descricaoModal').text(descricaoFormatada)
})
replace seems right to me. It’s not replacing?
– Sam
Here:
modal.find('#descricaoModal').text(descricaoFormatada)would have to bemodal.find('#descricaoModal').html(descricaoFormatada)to the<br>function as HTML.– Sam
@Sam already this as html but still does not work.
– Guilherme Rigotti
replace is not working? What is not working?
– Sam
Replace is not working, wanted to replace by <br> tag but replace is not causing any effect.
– Guilherme Rigotti
try to do
var descricaoFormatada = descricao.toString().replace(/ /g,"<br/>")– Máttheus Spoo