title: Copying onclick event
body: <p>I have a jQuery function with basically makes an entire table row clickable, but copying a link and duplicating the link in each child cell in the row.  In my projects, some of the links may have onclick javascript events, so I need my function to be able to copy those events as well, but I am having trouble doing that.</p>
  
  <p>Here's my current function:</p>
  
  <pre><code>jQuery.fn.linker = function(selector) {
      $(this).each(function() {
          var from = $(selector, this);
          if (from.length &gt; 0) {
              var href = from.attr('href');
              if (href) {
                  var link = $('&lt;a href="' + $(selector, this).attr('href') + '"&gt;&lt;/a&gt;').css({
                      'text-decoration': 'none',
                      'display': 'block',
                      'padding': '0px',
                      'cursor': 'pointer',
                      'color': $(this).css('color')
                  });
  
                  $(this).children()
                  //.css('padding', '0')
                 .wrapInner(link);
              }
          }
      });
  };
  </code></pre>
  
  <p>I've tried different methods to copy events but can't seem to get it to work:</p>
  
  <p>1) from[0].events is always undefined:</p>
  
  <pre><code>if (from.size() &amp;&amp; from[0].events &amp;&amp; link.size()) {
  
      var events = from[0].events;
      link.each(function() {
          for (var type in events) {
              for (var handler in events[type]) {
                  jQuery.event.add(this, type, events[type][handler], events[type][handler].data);
              }
          }
      });
  }
  </code></pre>
  
  <p>2) This one seems to execute ok, but clicking on the copied links doesn't do anything</p>
  
  <pre><code>link.attr('onclick',from.attr('onclick'));
  </code></pre>