Rich-text Reply

Write a function inside the onClick intead of call the function

miguelm 12-15-15

Write a function inside the onClick intead of call the function

Hi,

 

I have this function

 

function loginclick932(){
$(".logoRewards").click();
}

 

and after I have this code, which is calling the function in an onClick:

 

$(".secondNav > ul").append("<li id=\"optimizely_575573324\"></li>");
$("#optimizely_575573324").replaceWith("<li id=\"optimizely_575573324\"><li><a href=\"#\" title='Login' onclick=\"loginclick932()\").click(); >Login</a></li>");

 

How can I write the function inside the onClick instead of declare first the function and after call it in the onClick? 

 

Thank you,

 

Level 2

Re: Write a function inside the onClick intead of call the function

Hi @miguelm,

 

You can define the function and call it inside the onclick event:

$(".secondNav > ul").append("<li id=\"optimizely_575573324\"></li>");
$("#optimizely_575573324").replaceWith("<li id=\"optimizely_575573324\"><li><a href=\"#\" title='Login' onclick=\"loginclick932=function(){$('.logoRewards').click()}; loginclick932();\" >Login</a></li>");
Harrison Krat
Solutions Architect | Optimizely, Inc.
harrison@optimizely.com
 
miguelm 12-16-15
 

Re: Write a function inside the onClick intead of call the function

Thank you @Harrison_Krat  it works perfect!  Smiley Very Happy

 

I tried to do it, but I was making a mistake because was not working.. :!

Level 2