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 6787807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:24:36+00:00 2026-05-26T17:24:36+00:00

I have the following function: simpleModal: function (data, id) { var responseHtml = data;

  • 0

I have the following function:

simpleModal: function (data, id) {

        var responseHtml = data;

        // Append the modal HTML to the DOM
        var modalInstance = $('body').append(modalHtml);

        $(modalInstance).attr('id', id);

        $(id).find('.uiModalContent').width(480);
        $(id).find('.uiModalContent').height(320);

        // Hide the modal straight away, center it, and then fade it in
        $(id).find('.uiModal').hide().center().fadeIn();

        // Dynamically load in the passed data from the call
        $(id).find('.uiModalContent').html($(responseHtml));
        $(id).find('.uiModalContent').removeClass('loading');

        $(id).find('.ModalClose').live('click', function (e) {
            e.preventDefault();
            $(this).parents('.uiModal').fadeOut(function () { $(this).parents('.uiModalWrapper').remove() });
        });
    },

when called like:

uiModal.simpleModal('<p>An error has occured</p>','TestError');

it should append the modal to the body with the passed content and give the modalHtml an id that is also passed. However it gets confused to appends the id to the body instead of the html. How do I get around this? Thanks

  • 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-26T17:24:37+00:00Added an answer on May 26, 2026 at 5:24 pm

    This is because the append method returns the element you are appending to, rather than the element you’re appending.

    Instead, you can use the appendTo method, and use it as follows;

    var modalInstance = $(modalHtml).appendTo('body');
    

    You also need to be using $('#' + id) as the ID selector as opposed to $(id); otherwise you’ll end up looking for all elements with the tag name of TestError.

    Additionally, you should seriously consider caching the result of $('#' + id); you’re performing the same DOM lookup operation 6 times; which is totally unnecessary, as you have exactly the same jQuery object cached in var modalInstance; replace all instances of $('#' + id) to modalInstance

    This point applies to $(id).find('.uiModalContent') as well; cache it!

    var uiModelContent = modelInstance.find('.uiModalContent');
    uiModelContent.height(320);
    uiModelContent.width(480);
    uiModelContent.html($(responseHtml));
    uiModelContent.removeClass('loading');
    

    Although you can also chain your methods for the same result;

     modelInstance.find('.uiModalContent').height(320).width(480).html($(responseHtml)).removeClass('loading');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that is pulling data from a database. The ajax
I have the following function: var emptyFields = false; function checkNotEmpty(tblName, columns, className){ emptyFields
I have the following function: function getLevel(points) { var level = -1 + Math.sqrt(4
I have the following function: <script type=text/javascript> function changeText(elem){ var oldHTML = document.getElementById(elem).innerHTML; var
I have following function in jquery: $('canvas').createWindow('xyz', 500, 600); And js-code behind is: var
I have following function in C++ int readData ( Class1 *data) { //StartTime try{
I have the following function defined: function _getUserMatches(url, mDist, ui) { var dataString =
I have the following function that prunes a tree data structure : public static
I have the following function: var randomImages = [bgr1,bgr2,bgr3,bgr4,bgr5,bgr6]; var rndNum = Math.floor(Math.random() *
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)

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.