Solved

copy handler

Posted on 2013-01-12
1
155 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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)

895 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

11 Experts available now in Live!

Get 1:1 Help Now