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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:06:54+00:00 2026-06-12T19:06:54+00:00

I’ve noticed that the .end() cannot get back the old set of jquery elements,

  • 0

I’ve noticed that the .end() cannot get back the old set of jquery elements, if I set jQuery elements in find().

According to jquery document http://api.jquery.com/find/ . It should accept jQuery object. Is it a bug? Or something I should know ? Thank you very much.

<section>
<div id="myDiv" style="display:none;">
    This is my DIV ... <span id="p-text"></span>
</div>
</section>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
window.onload = function(){

var $m = $('#myDiv');
var $t = $('#p-text');

// this will show myDiv
$m.find('#p-text').text('blabla').end().show();

// this will not show myDiv
$m.find($t).text('blabla2').end().show();
}
</script>
  • 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-12T19:06:56+00:00Added an answer on June 12, 2026 at 7:06 pm

    Re-EDIT:

    The difference is between $m.find(<string selector>) and $m.find(<jquery object>);

    Assumptions

    • The end() function return an object called prevObject (this is a not-documented public property of jquery stack), stored in returned jquery stack.
    • This property is set, indirectly, in function like find and filter
    • The method find behaves differently depending on type of argument (string or jquery Object)

    what happens

    • if the argument is <String selector> then it store the current jquery object in this prevObject property.
    • if the argument is <jquery object> then store the RETURNED stack in this property.

    indeed:

    $m.find('#p-text') // return a stack with element <span> and prevObject = $m
    .text('blabla') // change simply the text
    .end() // return the stack stored in prevObject (ie $m)
    .show(); // show the current stack (ie $m)
    

    and it works because $m is the element with display:none

    in the second case:

    $m.find($t) // return a stack with <span> element BUT the prevObject property is the $t element
    .text('blabla2') // again change the text
    .end() // return the stack stored in prevObject (IE $t now!!)
    .show(); // show the current stack (ie $t)
    

    and it does NOT works because the $t element is only a child of hidden element.

    Why?

    The find method use internally the method jQuery( selector ).filter if the selector is a jquery object. Here the piece of source code

    if ( typeof selector !== "string" ) {
        return jQuery( selector ).filter(function() { // <---- here
            for ( i = 0, l = self.length; i < l; i++ ) {
                if ( jQuery.contains( self[ i ], this ) ) {
                    return true;
                }
            }
        });
    }
    

    This call return a stack with prevObject filled with jQuery( selector ) instead of original stack. In your case the prevObject is the jquery object $t instead of $m.

    I think that’s a bug resulted from a objectless use of jquery library (your code has no sense because you should write simply $t.text('blabla2').show())

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

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.