My question: why the function call $("#p1").click() doesn't simulate users to click on "p1"? i.e. the "$(this).hide() is not executed at all.
but if I register the click event in $(document).ready(function() {});, then $("#p1").click() works! Why?
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$("#p1").click(function(){
$(this).hide();
});
$(document).ready(function(){
$("#p1").click(); <== this line doesn't work! why?
});
</script>
</head>
<body>
<p id="p1">If you click on me, I will disappear.</p>
</body>
</html>