How can I convert this script so that it fires onload rather than using a button click? I’m trying to understand this but it is not sinking in.
<script type="text/javascript">
jQuery(function($){
// unordered list
$('button.item').click(function(){
$('ul').foo();
});
});
</script>
</head>
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
</ul>
<button class="item">foo</button>
You can use something like this:
Is better if you call it at the end of the file, just befor closing the
<body>tag.And the function
$(document).ready(function(){...is the one you use whn you need to do something when the page loads.I recommend you to check the jQuery tutorials in w3schools: http://www.w3schools.com/jquery/default.asp
Document.ready is faster to react than window.onLoad