Reputation:
I am trying add simple bootstrap jquery functionality in cakephp 2.5.5but i dont know how to add script in view.Please suggest me some code?
in webroot jquery folder i have created custom.js
$(document).ready(function(){ $("#hide").click(function(){ $("p").hide(); }); });
in view i have
<?php
echo $this->Html->css('index');
echo $this->Html->script('custom');
?>
<p ><?php echo "some text"; ?></p>
<?php echo $this->Form->button('click me',array('id'=>'hide'));?>
Upvotes: 3
Views: 480
Reputation: 223
Say path to custom.js file is in webroot/js/jquery/custom.js, then you can have it in view with
<?php echo $this->Html->script('jquery/custom.js'); ?>
If the path is not in the folder webroot/js (say webroot/jquery/custom.js), then specify the whole path to the file like
<?php echo $this->Html->script('/jquery/custom.js'); ?>
Always add the line below at at the end as described here
echo $this->Js->writeBuffer();
Upvotes: 1