tags:

views:

59

answers:

4
<script type="text/javascript">
$('.pp').click(function()   {
    alert();
});
</script>

<p class=pp>asdf</p>
<p class=pp>asdf</p>
<p class=pp>asdf</p>

Why the function is not called on click event?

It must be very silly and stupid question, but I don'w know what I'm missing.

+10  A: 

Because the DOM hasn't been loaded yet:

$(document).ready( function() {
  // ...your code...
} );
thenduks
A: 

This is purely because you are attaching a click event to a node that doesn't actually exist yet. Put the code after the HTML nodes, or call that upon the load or DOMContentLoaded events.

Delan Azabani
+1  A: 

should be

<script type="text/javascript">
$(function(){
    $('.pp').click(function(){
        alert();
    });
});
</script>
BritishDeveloper
A: 

or

<script type="text/javascript">
$(document).ready(function(){
    $('.pp').click(function(event){
        alert();
    });
});
</script>
Vina