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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:46:24+00:00 2026-06-13T01:46:24+00:00

I am trying to access an html element’s prototype through jQuery’s .data() function. So

  • 0

I am trying to access an html element’s prototype through jQuery’s .data() function. So far I am very confused.

This is my code:

// start prototype definition for myWidget
var myWidget = function() { 
    console.log('my widget is alive.');
    return this; 
};

myWidget.prototype.chosenSelect = [];

myWidget.prototype.init = function() {
    this.chosenSelect = $('#chooseMe');

    // test 1
    console.log(this.chosenSelect.data());

    // test 2
    console.log(this.chosenSelect.data('chosen'));

    // test3
    console.log(this.chosenSelect.data('Chosen'));

    // test4
    var chosenObject = this.chosenSelect.data();
    console.log(chosenObject.chosen);
};

Test 1 from above returns an object that I was able to look through using Chrome devtools. The object looks like this:

Object
    chosen: Chosen
        changeCallbacks: Array[0]
        etc
        etc
        etc

I want to access the chosen object in that data object. but tests 2 through 4 all return undefined. What could I be doing wrong?

Edit

The prototype is being added to the element from another library. This is an excerpt where the assignment occurs:

Chosen.prototype.init = function(select, zidx, isIE7) {
this.select = select;
this.select.data('chosen', this);
  • 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-13T01:46:25+00:00Added an answer on June 13, 2026 at 1:46 am

    You can access the data object as follows. Here’s a working example.

    // Set some data on the widget.
    jQuery.data($('#chooseMe')[0], "Chosen", {chosen: "Hello!"});
    
    var myWidget = function() {
        console.log('my widget is alive.');
        return this;
    };
    
    myWidget.prototype.chosenSelect = [];
    
    myWidget.prototype.init = function() {
        this.chosenSelect = $('#chooseMe')[0];
    
        // test 1
        console.log(jQuery.data(this.chosenSelect));
    
        // test 2
        console.log(jQuery.data(this.chosenSelect, "Chosen"));
    
        // test3
        console.log(jQuery.data(this.chosenSelect, "Chosen").chosen);
    
        // test4
        var chosenObject = jQuery.data(this.chosenSelect, "Chosen");
        console.log(chosenObject.chosen);
    };
    
    
    myWidget.prototype.init();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to access an HTML table from code behind, and set its
I am trying to add a data attribute to a html element. The data
I'm trying to access a data attribute ('maxselection') of several html elements while attaching
I'm trying to access an HTML element using Selenium (Java) but am currently having
I am trying to access only the ELEMENT for toc-chapter number (1 in this
Trying to access a Servlet from a button on HTML page //Html Page FORM
I am trying to access all the data from database listOfFolder table folder and
I am trying to access a file for xml parsing with this: InputStream inputStream
I'm trying to access the html contents of an script block with the type
I have this html code for embedding a video in an aspx page: <OBJECT

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.