In this code :
function onHover_(){
$('p').css('background-color', 'red') ;
}
$( document ).ready(function() {
//1
$('p').click(onHover_);
//2
$('p').click(onHover_());
});
In the first line the onHover_
function gets executed (as I expected) after I'd click on a <p>
tag. In the second line the onHover_()
gets exectued right away after the document is ready, meaning it doesn't wait for an click
event !
Simply, why ?
Here's a jsFiddle to test the code.
Found this thread on STO but the result is not what the accepted answer would've prediced.