jquery - How to interact with a javascript element -


I am using AC editor (via jquery-ace-rails gem) to convert textarea into code editor I am

  & lt; Textarea class = "my-code-area" rows = "4" style = "width: 100%" & gt; Puts 'foo' & lt; / Textarea & gt; & Lt; Script & gt; $ (Document) .ready (function () {$ ('. My-code-area'). Ace ({subject: 'twilight,' lang: 'ruby'})}}; & lt; / script & gt;   

I want to create a link on the page to insert text in the editor:

  & lt;% = link_to 'Insert', '# ',: Onclick =>' ace.insert ("some good"); '& gt%;   

Any help appreciated - I did not work with Javascript before

This can be relevant: especially in the "Access to ACE Code Editor Examples" section.

You can use ace by using the property of the data in the Ace example

Then try jquery ('. My-code-area'). Data ('ace'). Ace.insert ("some good"); Ace.Instant ("some cool");

Instead of using inline event handlers, try using jQuery event handlers so add a class or id to the link, then remove the inline event handler

  jQuery ( Function ($) {$ ('. My-code-area '). Ace ({subject: 'twilight', lang: 'ruby'}); Var decorator = $ ('.my-code-area'). Data ('Ace') Editor; // ACE code editor example var ace = decorator.ac; // Enter the id in the link -international $ ('# insert-link'). Click (function () {ace.insert ("some good");})});   

Demo:

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -