Solved

copy handler

Posted on 2013-01-12
1
154 Views
Last Modified: 2013-02-14
I'm wondering if there is a way using jQuery to copy a handler onto another component. What Im trying to do is convert one element to another, but if there is a handler, Im want to copy it to the new element.

So for example:-
$(document).ready(function() {
      var elm = $('#btnTest');
      var value = $(elm).val();
      var myFunction = $(elm).Click;
      var thisUID = uid();
      $('#wrapper').html('<div id="' + thisUID + '" class="childDiv">' + value + '</div>');
      $('#'+thisUID).click(myFunction);
    });

function uid() {
   var result='';
   for(var i=0; i<32; i++) {
       result += Math.floor(Math.random()*16).toString(16).toUpperCase();
       }
   return result
  }

Open in new window


Ive been reading a few articles about cloning handlers (hence having to put an ID in), but I cant get one working.

Ive put it on jsFiddle to show what Im trying to do http://jsfiddle.net/5yUwS/ in the hope someone can assist
0
Comment
Question by:tonelm54
1 Comment
 
LVL 1

Accepted Solution

by:
headshock earned 500 total points
Comment Utility
Are you trying to copy the ID handler and apply it to another element? If so I suggest any operations on the handler are done using .on and the previous instance is destroyed or renamed to avoid duplicate IDs. obviously use a class to to the event trigger.
$(".classname").on("click",function(event){
 // events
});

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now