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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:06:38+00:00 2026-05-25T14:06:38+00:00

I have been using this method for a while now having initially not put

  • 0

I have been using this method for a while now having initially not put any research into it.

$("div#panel-frame div.panel.txt select.fontsize").live('change', function ()
            {
                var parent = $(this).parents('div.panel.txt');
});

So as you can see from the code above, I’m trying to get access to a parent of select.fontsize. The parent I’m trying to get to is div.panel.txt – as you can see, I’m accessing it by saying $(this).parents(‘div.panel.txt’)

This method works but I’m wondering if there is a better way of doing it? Ideally I want it to be as fast and efficient as possible.

  • 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-25T14:06:39+00:00Added an answer on May 25, 2026 at 2:06 pm

    What you have inside your change function should be efficient enough, though if you know that the element you want is the direct parent, you should use .parent() instead of .parents(). As other people have said, if you don’t know whether it’s the direct parent, use .closest() instead of .parents().

    In theory, you can use this.parentNode to get the parent – regardless of its node or class names – with native DOM traversal (that is, without using jQuery), and that might be a bit quicker. However, you would need to write your own checks to make sure the node and class names match, so any gains you make would probably be lost again. This is basically what jQuery is doing under the hood anyway, and jQuery is very heavily optimised already.

    Your .live selector $("div#panel-frame div.panel.txt select.fontsize") is probably a bigger worry in terms of speed. .live() works by assigning an event to the body element, and then watching the targets of events as they bubble up. So, when any ‘change’ event hits the body, jQuery needs to check if it originated at something matching 'div#panel-frame div.panel.txt select.fontsize', which is a very slow operation, especially in older browsers.

    It would probably be quicker to just bind .live() to $(‘select.fontsize’), and then check if the select element is the kind you want within the event handler itself. That way, jQuery can use the browser’s native ‘getElementsByTagName’, which is a fast operation. Better yet, give your select.fontsize elements a more specific class name, so you know in advance that they’re the ones you want.

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

Sidebar

Related Questions

I have been using this copy method for quite a while, in lots of
I have been using this as a reference, but not able to accomplish exactly
How to write this in C#.NET, I have not been encountered using the ^
I been using the jquery ui for quite a while now. This is the
I have been digging around on this site and googling for a while now
I've been having this issue for a while now and was never really able
I've been stuck on this problem for a while now and have tried my
I have been using python for a while now and Im happy using it
So I have been searching for a solution for this a while now, and
It seems that altough I have been using NHibernate for a while now, 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.