Allow carriage return or new lines in tooltip (jquery)

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.
Post Reply
dzcadii
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Allow carriage return or new lines in tooltip (jquery)

Post by dzcadii » Sun Mar 22, 2015 4:37 pm

If you are wanting to have or allow carriage returns (<br />) in a jquery tool tip you can use one of these two:

:arrow: *Note: This uses a single "|" to indicate it should replace with "<br />"

1. Single line break:

Code: Select all

$(function () {
            $(document).tooltip({
				content: function(callback){
					callback($(this).prop('title').replace('|', '<br />'));
				}
			});
        });
2. Multiple line breaks:

Code: Select all

$(function () {
            $(document).tooltip({
				content: function(callback){
					callback($(this).prop('title').replace(new RegExp("\\|", 'g'), '<br />'));
				}
			});
        });

Post Reply