Adding javascript onto elements

Is there a way to add code to elements? In my case, I’d like to add in onclick events to a button, but is there a way to attach in-line JS to elements?
I’d like to add this code, specifically, to open a chat window for customers:
onclick="lcsShowChat(1); return false;"
…but I think a generic answer could help others as well.

Hello There,

Thanks for writing in! Regretfully there is no field or option where you can add the custom inline JS script. You may just add a button ID my-button-id or my-button-class class and then in Cornerstone custom js section, Custom JS and insert the following custom js code

(function($){
	$('#my-button-id, .my-button-class').on('click touchstart', function(e){
		lcsShowChat(1); 
		e.preventDefault();
	});
})(jQuery);

This may not work if lcsShowChat() is not loaded on the page.

That will likely work just fine, although adding in a section that allows us to assign on(whatever) events to elements would be a nice addition.

One other feature suggestion: the ability to add a note with elements (unseen anywhere but the editor) to track stuff like this; IE “Note: This button element has javascript attached to it in Custom JS! If you change or delete it, please also change/remove that function”

Hi There,

Thanks for the suggestion! we will definitely review it.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.