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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:40:52+00:00 2026-05-22T18:40:52+00:00

I have the following jQuery code: $(‘.save’).submit(function(e){ var formElement = $(this); var data =

  • 0

I have the following jQuery code:

$('.save').submit(function(e){
    var formElement = $(this);
    var data = 'id=' + $(this).attr('name') + '&' + $(this).serialize();
    var messageBox = $(this).next('.message');
    messageBox.html('<div class="pending">Saving... please wait...</div>');
    $.post('save.php', data, function(response) {
        messageBox.html(response);
        if(response.indexOf('success') != -1) {
            alert(formElement.closest('li').html());
        }
    });
    e.preventDefault();
});

And this is the HTML that it works with:

<ul class="entries">
   <li id="id8673" class="3">
      <div class="expand">
         <div class="name">...</div>
      </div>
      <div class="entry">
         <div class="description">...</div>
         <form action="index.php." method="post" name="rate8673" class="save">
            <div class="comments">...</div>
            <div class="controls">...</div>
         </form>
         <div class="message">
            <div class="success"></div> // Added by jQuery after form submission
         </div>
       </div>
   </li>
</ul>

Which alerts this when .save gets submitted:

<div class="expand">
  <div class="name">...</div>
</div>
<div class="entry">
  <div class="description">...</div>
</div>

If I update my jQuery code to:

...

alert(formElement.closest('li .entry').html());

...

It alerts this, as expected:

<div class="description">...</div>

But if I updated my jQuery code to this:

...

    alert(formElement.closest('li .expand').html());

...

It alerts this:

NULL

And it should be alerting this:

<div class="name">...</div>

And I can’t figure out why NULL? I have removed all javascript except for this function and all HTML elements are immediately available after the page loads, so what am I missing here? Is there a way what NULL is and where it got it from?

  • 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-22T18:40:53+00:00Added an answer on May 22, 2026 at 6:40 pm

    http://api.jquery.com/closest

    According the to jQuery documentation, .closest() only looks at ancestors. And div.name is not a direct ancestor of the form (it’s more like an uncle, but there’s no one selector for sibling of a parent).

    You could use:

    alert(formElement.parents('li').find('.expand').html());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery code which works fine. $('#onlyTwo').click(function() { $(#textarea3).attr(disabled, true); $(#textarea4).attr(disabled,
I have the following jquery code. var destTable = $(#numbers); $(document).ready(function() { $(#btnAdd).click(function() {
I have the following jQuery code-- $('div#mid_number_of_mail').mouseover(function () { setTimeout(function () { $('div.element_popup' ,this).stop().animate({
I have the following jQuery code: $('a[rel=close]').click(function() { alert('Close click!'); $('div#purchasePanel').hide(); }); This is
I have the following jquery-code: <script type=text/javascript> $(document).ready(function() { $ ('ul.image-list li:even').addClass ('even'); $
For example I have following jQuery code: var div1 = $(divs).next(); How do I
I have the following jQuery code (lizzy-doll is an image): var toTop = $('.lizzy-doll').css('top');
I have the following jQuery code, which works fine: $(document).ready(function () { $('#link1').click(function ()
I have the following jQuery code. I am able to get the following data
Without going into details, I have the following jQuery code: $(nav ul ul).each(function ()

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.