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

  • SEARCH
  • Home
  • 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 6200639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:24:22+00:00 2026-05-24T04:24:22+00:00

Assuming the following html structure : <div id=anId> <span id=1> aSpan </span> <span id=2>

  • 0

Assuming the following html structure :

<div id="anId">
    <span id="1"> aSpan </span>
    <span id="2"> anotherSpan </span>
</div>
<span id="3"> anOutsideSpan </span>

Is there a way to define a “global context” for jQuery selectors? Something like:

$(IDoNotKnowWhatToDoHere). SomethingAboutContext; // Defining the context as div#anID

$('span').doSomething; // Action only on span#1 and span#2 and not on span#3

$('span#1').doSomethingElse;

$('span').doSomethingStrange;

$('span#2').doSomethingCool;

$(SomethingAboutRemovingGlobalContext); //Removing the context

That way i can avoid doing this :

$('div#anId span').doSomething; // Action only on span#1 and span#2 and not on span#3

$('div#anId span').doSomethingElse; // Same as last code comment

$('div#anId span#1').doSomethingStrange; // Same as last code comment

$('div#anId span#2').doSomethingCool; // Same as last code comment

There is only 4 actions here but the code i’m working on has something like 100.

I want to avoid always repeting the div#anId.

  • Keep in mind it’s an example, not actual code.

  • My question is not about chaining.

  • 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-24T04:24:23+00:00Added an answer on May 24, 2026 at 4:24 am
    var $g = $.proxy($.fn.find, $("div"));
    $g('span').doSomething; // Action only on span#1 and span#2 and not on span#3
    $g('#1').doSomethingElse;
    $g('span').doSomethingStrange;
    $g('#2').doSomethingCool;
    

    So what your doing here is your creating a new selector that delegates to $("div").find and using that for all your selecting.

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

Sidebar

Related Questions

Assuming the following selector $(div span:first-child) applied in following html code John, Karl, Brandon
Assuming I have the following html div which I want to replicate its children,
Assuming several multiclass divs as demonstrated in the following HTML: <div class=class_one class_two class_three
assuming the following html (minus the comments and nbsp; etc that xQuery wont process
Assuming the following directory structure, htdocs/ images/ css/ .htaccess system/ index.php ... I would
Assuming I have the following ASP.NET HTML Code: <html> <head><title>Test Page</title></head> <body id=bodyID> <asp:Label
Assuming I have the following html: <ul id=a> <li>a</li> <li>b</li> <li>c</li> <li>d</li> </ul> And
First, you'll need to know the context. Browser: Chrome HTML: <ul> <li> <div>Hi!</div> </li>
Assuming I have a directory structure similar to: path_to_file/one/index.html How can I set my
Assuming, I have the following HTML: <ul class=topnav> <li class=><a href=/>Page 1</a></li> <li class=><a

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.