OzzC
OzzC

Reputation: 821

my jQuery alert() its not showing

Im starting to study jQuery and ajax, and Im doing my first test but it isnt working.

Im saying that on click on my class="test" I want to alert 'CLICK'.

But it is not working, do you see what Im doing wrong?

This is my jQuery:

   var read = $('.news');
    read.on('click','.test',function(){
        alert('CLICK');
    });

Upvotes: 0

Views: 50

Answers (1)

Adrift
Adrift

Reputation: 59779

You should only be using one class attribute:

echo '<p>'.$readNewsResult['content'].'<a class="test fancybox" href="#fancybox' . $readNewsResult['id_news'].'">Read More</a></p>';

And try wrapping your jQuery in a ready handler:

$(function(){
   var read = $('.news');
   read.on('click','.test',function(){
       alert('CLICK');
   });
});

Upvotes: 2

Related Questions