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

  • SEARCH
  • Home
  • 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 6842771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:08:31+00:00 2026-05-27T00:08:31+00:00

This is a really weird issue I’m having and I’m not really sure what

  • 0

This is a really weird issue I’m having and I’m not really sure what code to paste here because there’s quite a lot so I’m really looking for theoretical solutions I guess.

Basically, I’m using jQuery’s replaceWith() to add stuff to a box after a user logs in. It adds the exact same code as would be spat out by the php page (having checked a user has logged in). This was done so when they log in, jQuery adds their content but it should be exactly the same if they refresh or move to another page on the site.

This mostly works, except for a few form elements appearing to be out of alignment after jQuery replaces the content. After refreshing the page, they are aligned the way they should be.

Any ideas what might be happening? I’ve gone through Chrome’s dev tools looking at the CSS margins on these elements and their surrounding elements and the margins/padding etc. are exactly the same but display weird until refreshed!!

This is driving me nuts – has anyone seen this behavior before?

Cheers,

Scott

Screenshots might help –
jQuery - incorrect
PHP - correct

Here’s an example of the code:

<?php
    echo '<div id="accountpanel">
            <div id="selectclientbox">
              <form id="formSelectClient" action="" onsubmit="return false;">
                  <select id="selectClient">
                      <option>Client 1</option>
                      <option>Client 2</option>
                      <option>Client 3</option>
                      <option>Client 4</option>
                  </select>
                  <select id="selectAttribute">
                      <option>Change ID</option>
                      <option>Change Userame</option>
                      <option>Change Password</option>
                      <option>Change Name</option>
                      <option>Change Email Address</option>
                  </select>
                  <input id="changeDetail" class="coolbox" type="text" size="38" maxlength="128" />
                  <input id="updatebtn" type="button" value="update" onclick="updatedetail()" />
              </form>
              <form id="formUpdateClient" action="" onsubmit="return false;">

                  <section>
                      <label for="changeCurrency">Currency</label><input id="changeCurrency" class="text" type="text" maxlength="1" />

                      <input id="updatebtn2" type="button" value="update" onclick="updatecost()" />
                  </section>
              </form>
          </div>
    </div>';
?>

<div id="accountpanel2">
</div>
<script type="text/javascript">
            $('#accountpanel2').replaceWith('<div id="accountpanel2">' + 
                '<div id="selectclientbox">' +
              '<form id="formSelectClient" action="" onsubmit="return false;">' +
                  '<select name="">' +
                      '<option>Client 1</option>' +
                      '<option>Client 2</option>' +
                      '<option>Client 3</option>' +
                      '<option>Client 4</option>' +
                  '</select>' +
                  '<select name="">' +
                      '<option>Change ID</option>' +
                      '<option>Change Userame</option>' +
                      '<option>Change Password</option>' +
                      '<option>Change Name</option>' +
                      '<option>Change Email Address</option>' +
                  '</select>' +
                  '<input id="changeDetail" class="coolbox" type="text" size="38" maxlength="128" />' +
                  '<input id="updatebtn" type="button" value="update" onclick="updatedetail()" />' +
              '</form>' +
              '<form id="formUpdateClient" action="" onsubmit="return false;">' +

                  '<section>' +
                      '<label for="changeCurrency">Currency</label><input id="changeCurrency" class="text" type="text" maxlength="1" />' +
                      '<input id="updatebtn2" type="button" value="update" onclick="updatecost()" />' +
                  '</section>' +
              '</form>' +
          '</div>');
</script>
  • 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-27T00:08:32+00:00Added an answer on May 27, 2026 at 12:08 am

    Ok, looking at your example code I see a big difference between the HTML you are using to render the page and the code being “injected”.

    In the JavaScript string you have constructs that look like this (this is just an example, probably not the exact line that is causing the problem):

    '<select name="">' +
      '<option>Change ID</option>' +
      '<option>Change Userame</option>' +
      '<option>Change Password</option>' +
      '<option>Change Name</option>' +
      '<option>Change Email Address</option>' +
    '</select>' +
    

    And in the HTML it looks like this:

       <select name="">
         <option>Change ID</option>
         <option>Change Userame</option>
         <option>Change Password</option>
         <option>Change Name</option>
         <option>Change Email Address</option>
      </select>
    

    The result to the parser is two very different thing because the non JavaScript has a significant amount of whitespace and a carrage return + line feed between each element.

    This is the reverse of what I described — it seems you need the white space to get it to look right.

    There are two ways to solve this that come to mind right away. 1) Store your HTML templates in a script tag. I like this because it makes them easy to edit and you don’t have deal with lots of quotes and plus signs on every line. or 2) Add at least one space to the end of each line before the end quote and plus.


    Yes, I’ve seen this many years ago, tracked it down to a space between a tag end and a tag start. Should not matter, but did.

    I had something like this

    ..</tag1> <tag2>...
    

    And changed it to

    ..</tag1><tag2>...
    

    It solved the problem.

    I seem to remember this was more common with IE and list elements — but I could be remembering wrong.

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

Sidebar

Related Questions

This is weird and I'm not sure who the culprit really is. I'm doing
I'm seeing a really weird issue with this code and sample execution: https://gist.github.com/720278 The
I am not sure what is going on, but i get this weird issue
I am having this really weird issue with downloading files from within ASP.Net MVC
Well this is a really weird issue, I really didn't find anything on this
This is a really weird problem that I have been having. When I download
Boy, this one is really weird. I expect the following code to print 1990,
Ok, this one is really weird... I can't show code for it exactly cause
This is really weird. The images of my website are not showing properly. If
I have a weird issue with my CSS. Really can't figure this one 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.