Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6063801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:12:32+00:00 2026-05-23T09:12:32+00:00

I am using a simple jQuery plugin to style my javascript alerts. The problem

  • 0

I am using a simple jQuery plugin to style my javascript alerts. The problem being the usual methods for adding new lines does not appear to work. Here is the javascript for the plugin, any ideas?

(function($) {
$.fn.customAlert = function(options) {
    var settings = {
        'alertTitle' : 'Notice!',
        'alertOk'    : 'OK',
        'alertClose' : 'x',
        'draggable'  : false
    };

    if (options) $.extend(settings, options);

    if(document.getElementById) {
        window.defaultAlert = window.alert;
        window.alert = function(msgTxt) {
            if ($('#modalDiv').length > 0) return; // Only ever show one alert

            // The modal div to block out the rest of the document whilst the alert is shown
            var modalDiv = $('<div></div>');
            modalDiv.attr('id', 'modalDiv');
            modalDiv.height($(document).height()); // Make overlay cover the whole window

            // The alert container
            var alertDiv = $('<div></div>');
            alertDiv.attr('id', 'alertDiv');

            // The alert title
            var titleH1 = $('<h1></h1>');
            titleH1.addClass('titleH1');
            titleH1.text(settings.alertTitle);

            // The alert text to display
            var msgP = $('<p></p>');
            msgP.text(msgTxt);

            // OK button - will remove/close the alert on click
            var okBtn = $('<a></a>');
            okBtn.addClass('okBtn');
            okBtn.text(settings.alertOk);
            okBtn.attr('href', '#');

            // X button - will remove/close the alert on click
            var closeBtn = $('<span></span>');
            closeBtn.addClass('alert-close');
            closeBtn.text(settings.alertClose);

            // Append elements to document body
            alertDiv.append(titleH1);
            alertDiv.append(msgP);
            alertDiv.append(okBtn);
            alertDiv.append(closeBtn);
            $('body').append(modalDiv);
            $('body').append(alertDiv);

            // Center alert on page
            $('#alertDiv').css('top', ($(window).height()/2) - ($('#alertDiv').height()/2)+'px');
            $('#alertDiv').css('left', ($(window).width()/2) - ($('#alertDiv').width()/2)+'px');

            // Make draggable
            if (settings.draggable && $('#alertDiv').draggable) {
                $('#alertDiv').draggable({
                    handle: 'h1',
                    opacity: 0.4
                });
                $('#alertDiv h1').css('cursor', 'move');
            }

            // Bind OK button to remove/close alert
            $('#alertDiv .okBtn, #alertDiv .alert-close').bind('click', function(e) {
                $('#alertDiv').remove();
                $('#modalDiv').remove();
                e.preventDefault();
            });
        };
    }
};
})(jQuery);

I am guessing its a case of in this above finding /n and adding a <br> or </p><p>. I am unsure how to do that if even possible though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:12:33+00:00Added an answer on May 23, 2026 at 9:12 am

    Change this line:

         msgP.text(msgTxt);
    

    to

        msgP.html(msgTxt);
    

    and I think then you can use <br /> and other html tags.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery-1.4.2 library and jquery.validate.js plugin to validate a very simple form.
I'm using jQuery Validate Plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ Simple demo: <input type=text name=email class=required email />
I'm using jQuery UI's draggable and droppable libraries in a simple ASP.NET proof of
I'm using jQuery to post a form to a php file, simple script to
I'm trying to create a simple toggling sidebar using jquery, where it expands and
I have a simple HTML. I am using the JQuery for AJAX purpose. Now,
I have a simple html page with a div. I am using jQuery to
I have a simple html block like: <span id=replies>8</span> Using jquery I'm trying to
I have a simple html form that I've added validation to using the JQuery
Am using coda_bubble jquery plugin, and i need to make my bubble pop out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.