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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:08:03+00:00 2026-06-12T03:08:03+00:00

jQuery currently uses window as its default element so any call like $(‘div’) will

  • 0

jQuery currently uses window as its default element so any call like $('div') will look for div tags inside window.

Is there any way to change defaults on jQuery like:

$.defaultRoot = $('.anyOtherRootElement');
$('div').text("Hello");

this will select any div inside the elements containing .anyOtherRootElement class.

Thanks in advance


Upate

just an update refining the question a bit more here:

I would like to perform the actions above based on external queries coming from external script which won’t know what defaultRoot is so they can still be calling what is supposed to be the current base, so in this instance, I’m afraid adding the a second parameter wouldn’t be an option, unfortunately.

And at the same time creating a function which returns defaultRoot.find(el) would prevent me of using first-level methods such $.trim, $.each, etc… so unfortunately that would not be possible as well.

  • 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-12T03:08:05+00:00Added an answer on June 12, 2026 at 3:08 am

    Ideally (for performance reasons) you’d want to use find()

    $.defaultRoot.find("div");
    

    Otherwise you can use the 2 argument form that sets a context

       $("div", $.defaultRoot);
    

    In general you don’t want to do these types of things implicitly since someone else could easily end up thoroughly confused when having to work with your code later. If you want to do it consistently and make it shorter you should create your own function to do so like:

    var $s = function(selector) {
      return $.defaultRoot.find(selector);
    }
    

    and then you’d just be able to use

    $s("div")
    

    or you could also do a scoped higher order function with something like

    var withScope = function(scope$) {
      return function(selector) {
        return scope$.find(selector);
      }
    }
    
    var $s = withScope($.defaultRoot);
    $s("div")
    

    If for some reason you really want to screw around with the default state for client code (begging for chaos IMO), you should look at the functional practice: currying.

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

Sidebar

Related Questions

I am currently developing a site for a client which uses the JQuery cycle
I'm currently using jQuery to make a div clickable and in this div I
I am currently using jquery corner for making a div round cornered. But the
My website currently uses a custom jQuery gallery system that I've developed... it works
I am currently working on rails3 application that uses jQuery. I have a javascript
Given: client-side javascript code (runs in browser, uses jquery etc). Currently the code is
I am currently trying to create a multi-page form that uses both jQuery and
Currently I am using jQuery fadeTO to fade in a div. However I have
I'm currently working on a PhoneGap application that uses jQuery, jQuery mobile and a
Ive been trying to create a MouseOver event like iTunes currently uses on thier

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.