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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:42:51+00:00 2026-05-31T08:42:51+00:00

How can I find the parent element that loads the children elements without explicitly

  • 0

How can I find the parent element that loads the children elements without explicitly declaring it from another function?

the jquery,

$(document).ready(function(){

        $('.load-child').load_child();

    });


    (function($) {

        $.fn.extend({ 

            load_child: function(options) {

                var o = $.extend({
                    target:'.parent'
                }, options);

                var $this = this;

                var $cm = this.click(function(e) {

                    var object = $(this);
                    var path = object.attr('href');

                    $(o.target).load(path, function(){

                        $this.child();

                    });

                    return false;

                });


                $this.child = function() {

                    $('.find-parent').click(function(event){

                        var object = $(this);
                        object.parents('.parent').css({background:'red'});

                        return false;
                    })

                };


                return $cm;

            }
        })
    })(jQuery);

index html,

<a href="child.php" class="load-child">load child</a>

<div class="container">

    <div class="parent">    

    </div>

</div>

child page,

<div>
    <div></div>
    <div></div>
    <div><a href="#" class="find-parent">click me</a></div>
</div>

I can get the .parent element above because I declare the parent name explicitly,

object.parents('.parent').css({background:'red'});

But what about if the parent name is unknown or is changed constantly? Is there any generic method to locate/ trace back to the element that is used to load the page?

The loaded page may have loads of div elements, so I can’t do this,

object.parent().css({background:'red'});

or

object.parents(div).css({background:'red'}); // this will go up to the very top of div element.

the jsfiddle page.

Edit:

solution

  • 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-31T08:42:53+00:00Added an answer on May 31, 2026 at 8:42 am

    These are your options:

    1. You mark the parent in some way (easiest is probably with a special class name) when you load the content. Then the content can search up the ancestor chain with .closest(".markerName") to find it from anywhere within the content.
    2. You know something about the structure of the loaded content so that the content knows where it’s top is and can go one above that to find the load parent.
    3. You store the load parent in a globally reachable javascript variable so the content can fetch that when it needs it.

    Note, I think you generally want to be used .closest(selector) instead of .parents(selector). You can read about it here.

    Edit – based on the question you ask in your comment:

    Storing the load parent in a global variable is my least recommended option, but since you ask how to do it this is how:

    When your load-child method does this:

    $(o.target).load(path, function(){
    

    you would just remember the o.target value like this:

    window.loadTarget = $(o.target);
    

    Then, window.loadTarget will be a global variable containing where you last loaded content.

    Personally, I would much prefer you use a special class name. So, you’d replace this:

    $(o.target).load(path, function(){
    

    with this:

    $(o.target).addClass("loadTarget").load(path, function(){
    

    and then, anywhere inside the content that you want to find the load target, you’d do this:

    $(this).closest("loadTarget")
    

    This second option avoids any new global variables and supports multiple loadTargets at the same time.

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

Sidebar

Related Questions

I'm trying to find a jQuery selector that will match only the element that
I can find ample evidence that MongoDBs are always kept in the order given
Hy, Can someone tell me how can i find the page parent of an
I, for some reason, can't change the zIndex of an element using jQuery. I've
I have an element nested inside another element (i.e. parent element). The thing is,
Given an XElement is there a way to find out that element's index within
I have an XML structure where some elements are repeated inside the parent element,
I've been struggling to find a jQuery alternative that does exactly the same as:
I can't find a selector suited for my needs, that is get the first
Can anyone tell me if it's possible to find an element based on its

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.