How to Use Javascript inside Rmd Documents

Embedding <script> tag

We can just embed any html tag such as script or style directly inside the Rmarkdown text. They will be included in the final html output.

<script>window.alert("hello")</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>

Embedding {js} blocks

Or we can use the usual code blocks.

JQuery is already included with Rmarkdown. So, we can use JQuery functions directly:

```js
$('.title').text("hello")
```


<script type="text/javascript">
$('.title').text("hello")
</script>

 Tech    7 Mar, 2018

Any work (images, writings, presentations, ideas or whatever) which I own is always provided under
Creative Commons License Creative Commons Attribution-Share Alike 3.0 License

Mert Nuhoglu is a Trabzon-born programmer and data scientist.

You may also like...