An onclick handler like jQuery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lagon666
    New Member
    • Jun 2009
    • 22

    An onclick handler like jQuery

    In jQuery when I add onclick attribute for an element it doesn't add this attribute, but it works. So how does it works?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if you add anything via JavaScript, it doesn’t show up in the source code. and although I don’t know jQuery, I expect them to use Event Handlers.

    Comment

    • Lagon666
      New Member
      • Jun 2009
      • 22

      #3
      Thanks Dormilich

      But if you had Firebug installed on Firefox you can see ondemand edits in page source. (by using Inspect Element)

      if you run this code it will add in source coder:
      Code:
      document.getElementById("my_element").onclick = 'function(){ alert("Hello!"); }';
      But when i use jQuery it doesn't add anything to page souce.

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        as I said, if jQuery uses Event Handlers (that’s not event attributes), you won’t see anything in the code.

        Comment

        • Lagon666
          New Member
          • Jun 2009
          • 22

          #5
          Well
          Can you aid me to know more about this Event Handlers. How can i create something this?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            the standard way to create event handlers:
            Code:
            elem.addEventListener("event", callback, capture);
            // elem - the HTML element concerned
            // event - event type (e.g. "click")
            // callback - the name of the function to execute
            // capture - boolean indicating whether to fire in capturing or bubbling phase

            Comment

            • Lagon666
              New Member
              • Jun 2009
              • 22

              #7
              Great, Thanks man!!!

              Comment

              Working...