JavaScript jQuery replacing letters with HTML

I am pulling some text from a database and I have , and I would like to replace them with <br> don't really know why it's not working any ideas?

JS Code

$( document ).ready(function() {
    //.MoreInfoText
    var $infotext = $('.MoreInfoText').text().replace(/\+/g, '<br>');
    $.each($infotext, function() {
        $('.MoreInfoText').text($infotext);
    });
});

Text as its coming from the DB: Ryan open 30/01/1998, ryan added numberOFIteams of NameOFIteams

Answer:1

It should be .replace(/,/g,"<br>") so all ,s get replaced with <br>. Right now it's replacing + with <br>.

Also to iterate over every element with class MoreInfoText replacing , with <br> modify your code like this:

        $('.MoreInfoText').each(function() {
            var text = $(this).text().replace(/,/g, '<br>')
            $(this).html(text);
        });
Answer:2

Try to use the following code:

$( document ).ready(function() {
    //.MoreInfoText
    var $infotext = $('.MoreInfoText').text().replace(',', ' ');
    $.each($infotext, function() {
        $('.MoreInfoText').text($infotext);
    });
}); 
Answer:3

I need to make the array 'places' display its contents in the list. My problem is my function. I know I'm not doing it right. Can anyone help? Do I need to use getElementsByTagName? <body> ...

I need to make the array 'places' display its contents in the list. My problem is my function. I know I'm not doing it right. Can anyone help? Do I need to use getElementsByTagName? <body> ...

  1. make this array
  2. make array python
  3. make array golang
  4. make array java
  5. make array javascript
  6. make array matlab
  7. make array php
  8. make array unique javascript
  9. make array c++
  10. make array in jquery
  11. make array numpy
  12. make array empty javascript
  13. make array js
  14. make array strictly increasing
  15. make array from string
  16. make array of zeros python
  17. make array from object javascript
  18. make array from string php
  19. make array from string javascript
  20. make array bash

I am testing emit and listen methods with VueJS to learn how to use it. I get some strange results, I don't understand. I would expect my function initMap() is called and the console is logging, which ...

I am testing emit and listen methods with VueJS to learn how to use it. I get some strange results, I don't understand. I would expect my function initMap() is called and the console is logging, which ...

  1. vuejs event handler
  2. vuejs event handler parameters
  3. vuejs event handler component
  4. vuejs event listener
  5. vuejs event listener on component

I have been unable to find any examples of RSA-OAEP encryption in IE11. Here's a snippet of my implementation, in which I am given a very vague error. function convertStringToArrayBufferView(str)...

I have been unable to find any examples of RSA-OAEP encryption in IE11. Here's a snippet of my implementation, in which I am given a very vague error. function convertStringToArrayBufferView(str)...

I was wondering if it is possible to override "undefined" for uninitiated keys of an object such that: var obj={} console.log(obj.randomKey) output in console: 0 I am well aware that I "forgot" to ...

I was wondering if it is possible to override "undefined" for uninitiated keys of an object such that: var obj={} console.log(obj.randomKey) output in console: 0 I am well aware that I "forgot" to ...