Include JavaScript Only on a Specific Page in Magento 2

javascriptmagento2

I'm using magento 2 and I would like to include a javascript file , '' just into a page , for example about us page.. which file should I edit to do that, so I can add that code ?

Best Answer

You can go to cms -> pages and in the content of the page you want, add the javascript directly like i did in about us page

<script type="text/javascript">
$j=jQuery.noConflict();
$j(".logo").click(function(){
alert("The logo was clicked.");
 });
</script>

Then when i click on logo on about us page only it will alert

Or there is another preferred way to do this by adding this code in js file and load that js file in cms -> page -> design tab in layout update xml.