2

I am using the following code to allow line breaks in the JQuery UI tooltip function.

$(function() {
    $( document ).tooltip();

    $('.linebreak').tooltip({ 
        content: function(callback) { 
            callback($(this).prop('title').replace('|', '<br />')); 
        }
    });
});

The problem is that it only replaces the | to <br /> on the first occurrence and then just leaves the | in place for the rest.

Is there a way to replace all of them, not just the first?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
MRC
  • 555
  • 2
  • 10
  • 30

3 Answers3

4

To perform a global replacement you can use g:

Try this

callback($(this).prop('title').replace(/\|/g, '<br />'));

More infor is HERE.

nrsharma
  • 2,532
  • 3
  • 20
  • 36
2
replace(/\|/g, '<br />')

Have a look at this previous SO answer: What does the regular expression /_/g mean?

See this fiddle: http://jsfiddle.net/U3VxQ/

Community
  • 1
  • 1
Steve Claridge
  • 10,650
  • 8
  • 33
  • 35
1

use regular expresion Try this

.replace(new RegExp('|', 'g'), '<br/>')
Saurabh
  • 1,007
  • 2
  • 10
  • 24