In my helper, I have a function that is dynamically creating multiple . I want the onclick event to trigger a controller function : I tried the following code :

accordionWholeDiv.setAttribute('onclick', '{!c.unfoldAccordion}');

but it gives me this error : Error my brower gives me

I tried many solutions but couldn't find one working... Can somebody help me ? Thank you :-)

  • c in your javascript controller is referencing an apex controller method. Are you trying to call apex? – TemporaryFix Jan 22 '19 at 16:09
  • No I'm simply trying to tie the onclick event to a controller function ! – metheM Jan 22 '19 at 16:11
  • Does unfoldAccordion function already exist in your component's controller? – Jayant Das Jan 22 '19 at 16:12
  • can you add this event to the element mark up? <input type="button" onclick="{!c.unfoldAccordion} value="unfold""/> – TemporaryFix Jan 22 '19 at 16:13
  • Yes the unfoldAccordion function exists in my controller. And when I code an element in my component and set the onclick to call this particular controller function, it works as expected ! – metheM Jan 22 '19 at 16:15

if you can make the dynamic created element to be a component, you can then add the onlick event logic on that "normal" component controller

  • Yes this is a solution, though I have to rethink some of the architecture... I will give it a try later, will give feedbacks thanks ! – metheM Jan 22 '19 at 16:23
  • it will also be easier to manipulate/change later on, good luck. – Gil Grencho Jan 22 '19 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.