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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:00:35+00:00 2026-06-09T15:00:35+00:00

I have a selector where I get the first element like that: $(#MyControl)[0] Is

  • 0

I have a selector where I get the first element like that:

$("#MyControl")[0]

Is it possible to get the element with a function other than accessing the elements like a array?

What I want to do with that is to pass this element to a function with .call() to defines the context.

Here is an example:

$(document).ready(function () {
    $(document).on("change", "#MyControl", setActivityControlsState);
});

setActivityControlsState: function () {
    var selector = "#automaticActivityCreation";

    if ($(selector).length > 0) {
        if ($.isNumeric(this.value) && this.value > 0)
            $(selector).show();
        else
            $(selector).hide();
    }
}

referenceFormOnSuccess: function (data) {
    setActivityControlsState.call($("#MyControl")[0]);
}

As you can see in the refreshFormOnSuccess function, I must defines ‘this’ with $(“#MyControl”)[0].

I just want to know if is there a better way to do that.

Note that I don’t want to access the value of my control with something like $(this).val()

  • 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-09T15:00:36+00:00Added an answer on June 9, 2026 at 3:00 pm

    May I suggest a small re-structuring that mitigates that need:

    $(document).ready(function () {
        $(document).on("change", "#MyControl", setActivityControlsState);
    });
    
    setActivityControlsState: function () {
        // cache jquery object instead of just the selector 
        // for better memory management
        var automaticActivityCreation = $("#automaticActivityCreation");
    
        if (automaticActivityCreation.length > 0) {
            if ($.isNumeric(this.value) && this.value > 0)
                automaticActivityCreation.show();
            else
                automaticActivityCreation.hide();
        }
    }
    
    referenceFormOnSuccess: function (data) {
        // fire the change event which will tap 
        // the listener you set up in .ready
        $("#MyControl").trigger('change'); 
    }
    

    but if you really want to get the object with jquery you do have some options:

    // jQuery select #MyControl and get as dom element with array
    $("#MyControl")[0]
    
    // jQuery select #MyControl and get as dom element with .get
    $("#MyControl").get(0)
    

    but because you are using an element with an ID and you can only use a single ID at a time you really don’t need jquery for this

    document.getElementById('MyControl')
    

    or

    referenceFormOnSuccess: function (data) {
        setActivityControlsState.call(document.getElementById('MyControl'));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a calender selector that looks like <asp:ImageButton ID=calStartImage runat=server ImageUrl=../images/SmallCalendar.gif AlternateText=Please select
I have a jQuery selector that queries elements by tag name and class. In
Lets say I have a selector $('.items') and I want to get every item
So I have a selector that need to be perform after certain amount of
Example: I have a selector like this, which I give to another method as
I have a jquery selector which looks like this: $(#MasterListDVWP tr td:contains(' + currentSchool
I have a jQuery selector that is running way too slow on my unfortunately
I have a bunch of elements like the following: <div class=droppableP id=s-NSW style=width:78px; height:63px;
I have a block of HTML that I would like to use as the
I have a selector like this: $list = $('ul.sortable'); for jQueryUI's sortable plugin. There

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.