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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:57:48+00:00 2026-05-15T16:57:48+00:00

I have the following DOM structure: <div id=module-main> <div id=module-crumbs> <h4>Hello</h4> </div> </div> When

  • 0

I have the following DOM structure:

<div id="module-main">
 <div id="module-crumbs">
  <h4>Hello</h4>
 </div>
</div>

When I place that in a document and view it, it works fine. But if I build it from jQuery like so:

$('#module-main').append($('<div id=\"module-crumbs\" />'));
$('#module-crumbs').append($('<h4/>').html('Hello'));

Instead of the H4 margins expanding within “module-crumbs” it’ll expand just beyond “module-main” … what is most confounding is that the DOM structure is exactly the same after jQuery runs. How does the browser calculate the margins and why does it matter if I do it through Javascript vs hand coding it if the results are the same? Any ideas?

Thanks!

Edit: While I marked the best answer as it re-wrote what I was doing in a much more readable manner, the real root cause of the problem ended up being collapsing margins that did not trigger with jQuery because the jQuery was calling module-crumb instead of module-crumbs and there was nothing to prevent the border from collapsing. Putting a 1px padding brought it together (a border would have worked as well).

  • 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-15T16:57:49+00:00Added an answer on May 15, 2026 at 4:57 pm

    The DOM resulting from the markup and that generated by jQuery is not the same – the html() method is not behaving as you expect it to.

    The H4 element in the initial markup contains only a single text node.

    To build the same DOM with jQuery, use:

    $('#module-main').append($('<div id=\"module-crumbs\" />'));
    $('#module-crumbs').append($('<h4/>').append('Hello'));
    

    For a more markup-like representation (which can often be easier to read), try:

    $('#module-main').append(
        $('<div id="module-crumbs" />').append(
            $('<h4/>').append('Hello')
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following DOM structure: /*:DOC += <div id='testDiv' class='testDivClass'><div id='innerTestDiv'></div></div><span id='testSpan' class='testSpanClass'><span
I have the following DOM structure (unordered list), that I would like to sort
I have the following dom structure: <div class=ui-tabs> <ul> <li class=ui-state-default ui-tabs-selected ui-state-active> <a
I have the following DOM structure: <div class=city> <div class=a>Delete</div> <div class=b>Selected</div> <div class=c>Delete</div>
I have the following structure: <form> <div class=content> ... </div> <div class=action> <p>Select <a
Have the following JS included in my HTML: document.observe('dom:loaded', function() { Event.addBehavior( { 'a.move-up:click':
I have the following code: import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; DocumentBuilderFactory factory =
I have the following XML document that I have to parse using python's minidom:
Been struggling with this one I have the following DOM Structure: <ol id=add_images> <li>
I have the following DOM structure / HTML, I want to get (just practicing...)

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.