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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:24:49+00:00 2026-06-03T19:24:49+00:00

When delegate with p tag, it does not work http://jsfiddle.net/peswe/wbVMV/4/ HTML: <p id=’test’> <div>box

  • 0

When delegate with p tag, it does not work http://jsfiddle.net/peswe/wbVMV/4/

HTML:

<p id='test'>
    <div>box 1
        <div>box in box1</div>
    </div>
</p>

​
JavaScript:

$('p#test').delegate('div','click',function(){
    alert('test');
})

Changing p#test to span#test or body, it works http://jsfiddle.net/peswe/wbVMV/3/

HTML:

<span id='test'>
    <div>box 1
        <div>box in box1</div>
    </div>
</span>
​

JavaScript:

$('span#test').delegate('div','click',function(){
    alert('test');
})

Please tell me something about it.Thank you very much!

  • 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-06-03T19:24:51+00:00Added an answer on June 3, 2026 at 7:24 pm

    This is how browser (HTML parser) works, since <div> is a Flow element and <p> is a Phrasing element, in most case an phrasing element cannot contain any flow element, this is called misnested tags, HTML parser would fix these issues magically with some certain steps:

    1. When reading <p>, it generates a <p> element
    2. When reading <div>, since <div> cannot reside in a <p> element, HTML parser closes the last <p> element, then open an <div> element
    3. When reading </div>, closes the <div> element
    4. When reading </p>, since previous <p> element is closed, parser recogonizes it as a <p> element missing a start tag, so parser automatically inserts an <p> start tag here to create a complete <p> element

    Thus, the final DOM construct is:

    <p id="test"></p> <!-- auto closed -->
    <div>
      box1
      <div>
        box in box1
      </div>
    </div>
    <p></p> <!-- auto generated -->
    

    It’s obvious that the <div> and <p> is at the same level, not forming a containing relation, so delegate fails here.

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

Sidebar

Related Questions

jQuery delegate function is giving 'not a function' error for my plugin. So I
I have a problem with selecting the correct element using the .delegate method. <div><span>Some
I have a plugin that changes the look of select html tag on all
I am aware that by default Java does not have the so-called eval (what
I have a tag <AboutUs> (having HTML tags) and I have stored the string
How would I change the html of a tag like so: $('#someId').html('<p>foo bar</p>'); while
I am not able to totally understand the flow of NSXMLParser and the delegate
delegate void DelegateTest(); DelegateTest delTest; Whats the difference between calling delTest.Invoke() and delTest() ?
I'm designing a delegate method that is called when the remote server needs input
I have this delegate in C#. public delegate string ACSharpDelegate(string message); How would I

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.