javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)
Instance Public methods
Returns a JavaScript tag with the content
inside. Example:
1 | javascript_tag "alert('All is good')" |
Returns:
1 2 3 4 5 | <script> //<![ CDATA [ alert( 'All is good' ) //]]> </script> |
html_options
may be a hash of attributes for the
<script>
tag.
1 2 | javascript_tag "alert('All is good')" , defer: 'defer' # => <script defer="defer">alert('All is good')</script> |
Instead of passing the content as an argument, you can also use a block in
which case, you pass your html_options
as the first parameter.
1 2 3 | <%= javascript_tag defer: 'defer' do -%> alert( 'All is good' ) <% end -%> |
Please login to continue.