Running jQuery from content area off canvas

Hi everybody. I am trying to run jQuery from an content area off canvas.
I placed the following code in the content field:

<script language="text/javascript">
$( "#target" ).keydown(function() {
  alert( "Handler for .keydown() called." );
});
</script>

<form>
  <input id="target" type="text" value="Hello there">
</form>
<div id="other">
  Trigger the handler
</div>

This however, does not seem to work. What am I doing wrong?

Hello There,

Thanks for writing in! Your html code is working. The issue here is your JS code. Please re check your code. As this is a 3rd party code, it is best that you consult the source of the code since troubleshooting a 3rd party code is beyond the scope of our support.

Thank you for your understanding.

Hi, Thanks for your reply. I have tried pretty much every setup to test if I can get a random snippet to work in a content area off canvas, but nothing seems to work. Is it possible at all? Perhaps javascript is not loaded because it’s ran in a modal view? I currently have the following snippet. I want a simple alert box if a button is pressed. The html is rendered correct, but the script cannot be called.

<input type="text" name="testName" id="testId"/>
<input type="button" value="Show Alert" id="testButton"/>

<script type="text/javascript">
$("#testButton").click(
function()
{
   alert('this is a test');
}
);
</script>

I got it to work. I needed to add the following before the script:
jQuery(
function($){
}
);

Fantastic, great to hear that you figured it out. :slight_smile:

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