Solved

copy handler

Posted on 2013-01-12
1
156 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
ID: 38839438
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

822 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