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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:31:15+00:00 2026-05-30T17:31:15+00:00

function $(id) { if (id) { if (window === this) { return new $(id);

  • 0
function $(id) {
    if (id) {
        if (window === this) {
            return new $(id);
        }

        this.e = document.getElementById(id);
        return this;
    } else {
        return about;
    }
}

$.prototype = {
    click: function () {
        this.e.onclick = function () {
            alert("hi..");
        }
    }
};

when I excute this code :

$("skg").click2();

it return alert msg.

But I want to add a callback function like this :

$("skg").click(function(){
    alert("hi SKG");
});

How to do 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-05-30T17:31:16+00:00Added an answer on May 30, 2026 at 5:31 pm

    Example 1

    $.prototype = {
        click: function (callback) {
            this.e.onclick = callback
        }
    };
    

    but if you want to parse the DOM element you can do something like this:

    Example 2

    $.prototype = {
        click: function (callback) {
            this.e.onclick = function() {
               callback.call(this); 
            }
        }
    };
    

    EDIT:

    Haha… Actually there is almost no difference.

    But if you want to parse some custom arguments to your callback you can do it in the last example:


    your call:

    var handler = function(arg1, arg2, arg3, ...) {
        alert("Some alert");
    };
    $("someID").click(handler); 
    

    Example 1:

    handler gets DOM element as this so:

    this = [HTML DOMElement]

    The first arguments in handler (called arg1 (can also be accessed throw the array like variable arguments as the first arguments[0])) contains the click’s event property.

    arguments[0] = [Event Object]


    Example 2:

    this = [HTML DOMElement]

    Thats all. But you have the ability to parse extra arguments to the hander:

    If your code is like this:

    $.prototype = {
        click: function (callback) {
            this.e.onclick = function(event) {
               callback.call(this, event, {custom: "argument"} ); 
            }
        }
    };
    

    The handler will get:

    arguments[0] = [Event Object] // Same as Example 1

    But see now:

    arguments[1] = [Object object]

    or more precise:

    arguments[1] = {custom: "argument"}

    And as before you can access it throw arg2 but also the array like arguments[1].


    When i say array like i mean:

    It have some of the same abilities as an array:

    The length property: .length (arguments.length).

    The 0-index naming: [n] (arguments[0], arguments[1], …)

    But none of the native array methods like sort, push, pop, splice.

    Even more but 🙂 (And just a site note)

    You can use array like objects in with native array method:

    Lets say the arguments is like this: handler("a", "b", "c", "d")

    and you only want the the 2th argument and higher:

    var args = [].splice.call(arguments, 0, 1)

    Now args is a native array with: ["b", "c", "d"].

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

Sidebar

Related Questions

Here is my spaggeti code $(#table_exams tbody tr).click(function () { window.location.hash=# +$(this).attr(exam_ID); window.location.href=/medilab/prototypes/exams/edit?examId= +
Currently I got this code: function post_positive(id) { if (window.XMLHttpRequest) { xmlhttp = new
For example: (function() { var proxied = window.eval; window.eval = function() { return proxied.apply(this,
function icPageInit() { $(icImgDiv + icAlternate()).setOpacity(0); return true; } window.onload = icPageInit; This piece
When I pass 'this' to an anonymous function like so: MyClass.prototype.trigger = function(){ window.setTimeout(function(){this.onTimeout();},1000);
I have this script loaded on a page: (function() { window.alert('bookmarklet started'); function AjaxSuccess(data,
$(#table_exams tbody tr).click(function (event) { window.location.href=# +$(this).attr(exam_ID); window.location.href=/medilab/prototypes/exams/edit?examId= + $(this).attr(exam_ID) +&referer= + referer; row_select(this);
I have this function working <script type=text/javascript> $(window).scroll(function() { if ($(window).scrollTop() == $(document).height() -
function a (){ var b = null; if(window.XMLHttpRequest) b = new XMLHttpRequest(); else if(window.ActiveXObject)
<script type=text/javascript> function showHint(str) { if (str.length == 0) { document.getElementById(txtHint).innerHTML = ; return;

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.