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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:38:07+00:00 2026-05-27T10:38:07+00:00

I have the following HTML and jQuery code: <div id=outer> <p> <p>paragraph inside division.</p>

  • 0

I have the following HTML and jQuery code:

<div id="outer">
 <p>
    <p>paragraph inside division.</p>
    <h2>a heading</h2>
    <ul>
        <li>first item</li>
        <li>second item</li>
    </ul>
 </p>
</div>

jQuery:

$(function() {
    $divChildren = $('div#outer').children();
    $divChildren.each(function(){
        $(this).css('background-color', 'red'); 
    });
    alert($divChildren.length); 
});

From what I see, the no. of immediate children that <div id="outer"> has should be 1, but jQuery sees 4. Why is that?
However, if everyting inside ‘#outer’ was wrapped in another div (instead of <p>), then it sees only 1 immediate child (as expected).

EDIT: This is definitely a malformed HTML nesting issue (and thanks everyone for answering). But my question should, more appropriately, have been: Is jQuery aware of and imposes HTML nesting rules or is it the browser’s construction of DOM tree (which imposes nesting rules) and jQuery simply returns what is sees in DOM tree?

  • 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-27T10:38:08+00:00Added an answer on May 27, 2026 at 10:38 am

    your html code is invalid. you cannot put p tag inside p tag

    The paragraph element can be contained inside the elements “address”, “applet”, “blockquote”, “body”, “button”, “center”, “del”, “dd”, “div”, “fieldset”, “form”, “iframe”, “ins”, “li”, “map”, “noframes”, “noscript”, “object”, “td”, and “th”.

    HTML inline elements are the only elements that may be contained within a paragraph element.

    • a – Anchor which is used to create a link to another page or location
      in HTML.
    • abbr – Denotes an abbreviation.
    • acronym – Denotes an acronym.
    • area – Define a map region in an image.
    • b – Bold causes the text between the beginning and ending tag to be in bold font.
    • basefont – Allows font changes.
    • bdo – Overrides text direction with values of ltr (left to right) or rtl (right to left).
    • big – Sets size of text to big .
    • br – Break is a line break similar to a carriage return and line feed in most documents.
    • cite – Used to mark titles of articles or other publications.
    • code – Denotes computer program code.
    • dfn – Denotes a definition.
    • em – Denotes emphasis
    • font – Allows font changes.
    • i – Sets text between the tags to italics
    • img – Allows placement of a graphical image in the page.
    • input – Form input
    • ins – Denotes inserted text.
    • kbd – Denotes information typed from the keyboard.
    • param – Used to add additional parameters to the object or applet elements.
    • q – Used for short quotations
    • s – Strike through text
    • samp – Denotes a sample.
    • small – Sets text size to small
    • span – A container used to set special style to specific areas of the page.
    • strike – Sets text to have a line struck through it.
    • strong – Denotes strong emphasis which is basically bold
    • sub – Subscript
    • sup – Superscript
    • textarea – A form for multiline text input.
    • tt – Sets text style to monospaced teletype
    • u – Sets text underlined between the beginning and ending tag.
    • var – Denotes a variable in a program.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code (html,js,jquery) snippet ( http://jsfiddle.net/MUScJ/2/ ): <script type=text/javascript> function someFunc(){ html
I have the following HTML code: <script src=http://code.jquery.com/jquery-1.6.2.min.js></script> <div id=A style=width:100px; height: 100px; background:
I have the following code in JavaScript and jQuery: $(<li />) .html('Some HTML') I
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
I have the following HTML structure <div id=test-1-yay></div> ... bunch of code ... <div
I have the following JQuery Code concerning my tabs : $(#onglet>ul>li).click(function(){ $(#onglet ul li).removeClass('Selectionne').addClass(OngletPrincipal);
i have the following jquery code: $(document).ready(function() { $('.restrictiveOptions input[type!=checkbox], .restrictiveOptions select').change(function() { //
I have the following html snippet: <div id=contentX><h1>MyHeading1</h1></div> I could select with jQuery snippet
I have the following block of HTML code more than once <div id=page_1 class=page>
I have the following html (inside ASP.NET Repeater): <div class=team_member> <a class=teamMemberLink href='<%# Profile.aspx?uID=

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.