Adding onClick event dynamically via jquery not working in lightning

1.1K    Asked by NakamuraMatsumoto in Salesforce , Asked on Aug 8, 2021
<!--Required scripts.--> 
I have a filter button created dynamically, and there I am adding attributes using jquery .attr.
jQuery("document").ready(function(){ // Other code $(objFilterButton).attr('class', 'btn btn-default btn-lightning'); $(objFilterButton).attr('onClick', 'showFilter(event)'); });

The class gets added but, I cannot see the onClick event getting added on the dom. Is this a limitation in lightning?

enter image description here

Answered by Sarah Lee

 jquery onclick event dynamically don’t work in Lightning framework.


unfortunately, this is a limitation of the Lightning framework. Use $(elements).on(eventName, handlerRef) instead. Note that you should not try to use the old onevent style attributes anyways.



Your Answer

Interviews

Parent Categories