tonelm54
asked on
.clone to a differet type
Im trying to copy the onclick event from a list item, to a div.
Eg:-
What Id like to do is copy the onclick events to a generated div:-
I have tried:-
As well as:-
I have also tried using the clone method, which hopefully would copy all functions:-
Anyone have any other suggestions on copying handlers between different elements?
Thank you
Eg:-
<ul>
<li onclick="alert('hi1');" id="li1">1</li>
<li onclick="alert('hi12);" id="li2">2</li>
<li onclick="alert('hi3');" id="li3">3</li>
</ul>
What Id like to do is copy the onclick events to a generated div:-
<div>
<div id="div1">1</div>
<div id="div2">2</div>
<div id="div3">3</div>
</div>
I have tried:-
var myFunction = $('#li1').Click;
$('#div1').click(myFunction);
As well as:-
$('#div1').Click = $('#li1').click();
I have also tried using the clone method, which hopefully would copy all functions:-
$('#div1') = $('#li1').clone( true )
However from what I've read the clone cannot be used to copy handlers between events (eg list items and divs).Anyone have any other suggestions on copying handlers between different elements?
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
walter,
I already posted that answer.
I already posted that answer.
@ kozaiwaniec
You are right, sorry about that, just trying to help. p.s. made a new jsfiddle: http://jsfiddle.net/rUHzT/4/
You are right, sorry about that, just trying to help. p.s. made a new jsfiddle: http://jsfiddle.net/rUHzT/4/
ASKER
Ok, Im not sure Im reading off the same page here.
Im trying to copy an even from a div onclick event to a list onclick funtion .
I cant see the jsfiddle at the moment, as I just get a bad gateway error at the moment
Im trying to copy an even from a div onclick event to a list onclick funtion .
I cant see the jsfiddle at the moment, as I just get a bad gateway error at the moment
Made a little jsfiddle of your list example (assuming you are using jquery).
http://jsfiddle.net/rUHzT/
Hope this works for you.
greetz,
walter