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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:42:39+00:00 2026-06-16T02:42:39+00:00

I am facing some issues while getting elements of the sibling using jquery. I

  • 0

I am facing some issues while getting elements of the sibling using jquery. I will try to explain.

The following is the HTML that i am currently working on ..

<p class="paraclass1" id="amazing1">
  <span class ="pascal1">
    <div class='pascal'>
        <INPUT id= "chk1" value="on" type="checkbox" />
    </div>
  </span>
</p>
<p>
  <label class='lblclass'>this is a label </>
</p>

what i would like to do is to navigate and find all the children that are present in the second p tag (right now only a label is present) . The following is the Jquery code that i am working on ..

$('#chk1').click(function(){
  alert($(this).parents('p#amazing1').next().children().length)

 // alert($('#chk1').parent().parent().attr('class'));
});

http://jsfiddle.net/gj1118/vWQxD/5/

Any help would be appreciated.

Thanks

Edit
I am now trying to get the text of the label that is inside the second p tag element and its not working…. Is there something that I am missing .. ? I havent changed the fiddle yet , but since it was just a sample and since the tags were not being used, i let it remain like it for the sake of simplicity

  • 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-16T02:42:40+00:00Added an answer on June 16, 2026 at 2:42 am

    Your jQuery should work fine. The problem in this case is your markup. The p element can only contain “phrasing content“. The div element is not classed as phrasing content, so the browser will do its best to handle your markup by moving things around.

    Chrome simply moves the p element to become the previous sibling of the div.

    To fix the issue, you will need to change your markup. Your best bet may be to change the p element into another div. See an updated fiddle.


    Side note. You may want to consider changing the .parents() call to a .closest() call. The .parents() method can return multiple elements if they match the selector. In this case that’s not possible, but in the interest of maintainability, it could be a good change:

    $(this).closest('#amazing1').next().children().length
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing some issues while serializing objects (I am using JBoss Drools, and
I'm working using scriptaculous library. However I'm facing some issues with inclusion of the
I am facing some issues with jquery mobile . When I move from my
I am facing some issues while retrieving data from a doctrine pager object! Let
I am new to ASP.Net MVC 3, facing some issues while trying to implementing
I am using Eclipse Indigo (3.7) and facing issues while installing plugins onto it.
I have been facing some serious issues while executing this particular JSP page. CODE
I am facing some issues in loading a CSV file through SQL Loader. Here
Well, since I am facing some issues with OAuth implementation, I decided to go
Facing some issue in Talend Admin Console, the jobs that are running from IDE

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.