0

I am trying to split chain input value and want to add <br/> after every end of ,

<input type="text" class="title" />
<a class="into"></a>

$('.title').on('keyup change', function() {
  $('.into').text($(this).val());
});

Output :
demo1,demo2,
Want to output :
demo1 demo2

2 Answers 2

1

try this:-

$('.title').on('keyup change', function() {
   var p=$(this).val().split(',').join(',</br>');
  $('.into').html(p);
});

Demo

Sign up to request clarification or add additional context in comments.

Comments

0

You can make use of replace()

$('.title').on('keyup change', function() {
    var p=$(this).val().replace(/,/g, ',<br>');
  $('.into').html(p);
});

Fiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.