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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:20:58+00:00 2026-06-06T15:20:58+00:00

jQuery.widget(ui.test, { _init: function(){ alert(this.element.innerHTML); } }); How do I make it so when

  • 0
jQuery.widget("ui.test", {
    _init: function(){
        alert(this.element.innerHTML);
    }

});

How do I make it so when I am attaching this to a HTML element
It will alert the innerHTML (I know it does nothing, it is just to understand the basics).

<div id="baba">ja jaj</div>
<script>
$('#baba').test();//will alert "ja jaj"
</script>

What am I missing here?

What I missed:

My code was actually perfectly fine, EXCEPT, I assumed that this.element is an HTML element, while in reality it is a jQuery object. Hence innerHTML did nothing while html(), in the answer below, worked.

  • 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-06T15:21:01+00:00Added an answer on June 6, 2026 at 3:21 pm

    You’re missing the jQuery UI library. Simply attach it and yu’re good to go – http://jsfiddle.net/jUm5H/

    (function($) {
        $.widget("ui.test", {
            _init: function() {
                alert( this.element.html() );
            }
        });
    }(jQuery));
    
    $('#baba').test();
    

    UPDATE

    “To make sure that your plugin doesn’t collide with other libraries that might use the dollar sign, it’s a best practice to pass jQuery to an IIFE (Immediately Invoked Function Expression) that maps it to the dollar sign so it can’t be overwritten by another library in the scope of its execution.” – source

    So it’s basically just a good practice. You can ignore it and it will work – http://jsfiddle.net/jUm5H/1/ But it’s better to do it in a correct way from the beginning. It might save a lot of debugging time and frustration in the future projects 🙂

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

Sidebar

Related Questions

jQuery.widget(ui.test,{ _init: function(){ $(this.element).click(this.showPoint); }, showPoint: function(E){ E.stopPropagation(); alert(this.options.dir); } } $('#someEleme').test(); Right now,
Right now I have this jQuery('.widget-prop').keyup(function() { var prop = jQuery(this).attr('id'); var val =
I have code like: document.onmousedown = function(){ alert('test'); } Now, except the element with
I'm using this JQuery autocomplete widget . How can I make it automatically open
When creating a jQuery UI widget is it possible to make the namespace and
Dojo has this: http://download.dojotoolkit.org/release-0.4.3/dojo-0.4.3-widget/tests/widget/test_Select.html Similar to Google Auto-suggest. Does jQuery have anything similar?
Do you know how to instantiate JQuery UI widget by string? Let's illustrate it
I'm trying to make an image gallery using the jQuery UI slider widget. My
I have a jquery ui widget defined like this: $.widget(ui.someWidget, options: {}, _create =
I am using the jQuery-File-Upload widget (although I believe this question can generalize to

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.