Donal.Lynch.Msc
Donal.Lynch.Msc

Reputation: 3615

CakePHP and JQuery Integration

I am trying to get CakePHP working with JQuery. Below is the div that I have in place, and all I am trying to do is simply alert("CLICKED!"); whenever the below link is clicked.

<?php echo $this->Html->link('Link Click Me', '#', array('onclick'=>'return false;', 'id'=>'divId', 'class'=>'divClass')); ?>

I have the following files 'jquery-1.5.2.js' and 'js_file.js' in the 'js' directory of the 'webroot' folder in my project, and JQuery is working, but I cant seem to get this particular functionality working.

Any suggestions??

Code for jquery:

$(document).ready(function(){

    $('.divClass').click( function(){
        alert("TESTING!");
    });

});

And this is the view:

<?php echo $this->Html->link('Link Click Me', '#', array(  'id'=>'divId', 'class'=>'divClass')); ?>

I am still looking for an answer to this question guys....

Upvotes: 0

Views: 2340

Answers (2)

Donal.Lynch.Msc
Donal.Lynch.Msc

Reputation: 3615

The problem seems to be the fact that I didnt include these at the top of the view:

<!-- IMPORTS: -->
<?php $this->Html->css("css_file", null, array("inline"=>false)); ?>
<?php echo $html->script("jquery-1.5.2"); ?>
<?php echo $html->script("js_file"); ?>

Upvotes: 0

Calum
Calum

Reputation: 5316

Post your jQuery code for the alert.

You may need to use bind() instead of click().

Remove onclick="return false;" from the link and add return false; to the end of the jQuery click function.

Upvotes: 2

Related Questions