Tag html in Jquery

Asked

Viewed 37 times

0

I can’t get the tag <br> html in jquery.

$('#test').change(function(){
    $('#doenca_atual').val($('#doenca_atual').val()+" <br> "+$('#test option:selected').text());
});

Instead of jumping the line with the <br>, he simply put the <br> text-based

<br> Z98   Outr estados pos-cirurgicos <br> Z95   Presenca implantes enxertos cardiacos vasc

It would have to stay that way

Z98   Outr estados pos-cirurgicos 
Z95   Presenca implantes enxertos cardiacos vasc
  • 2

    But what is $('#current disease')?? One input, if it is, there is no break line in this element.

  • eh a textarea of html

  • 1

    textarea does not accept br you have to exchange for backslash N

1 answer

3


You imply that you are adding the options to a <textarea>, the line break for this element is not the <br>, but rather the \r\n. Also no need to replace all content, just add the new selection.

$('#test').change(() => {

  let selecionado = $('#test option:selected');

  if (selecionado.val() != "")
    $('#doenca_atual').append(`${selecionado.text()}\r\n`);

  //remove o item da lista
  selecionado.remove();
  //retorna a seleção para o primeiro item
  $('#test').val("");

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="test">
  <option value="">selecione</option>"
  <option value="doenca 1">doenca 1</option>
  <option value="doenca 1">doenca 2</option>
  <option value="doenca 1">doenca 3</option>
  <option value="doenca 1">doenca 4</option>
  <option value="doenca 1">doenca 5</option>
</select>
<br />
<textarea id="doenca_atual" rows="10"></textarea>

Browser other questions tagged

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