I have a click event function like so:
$('.expand2').click(function(e) {
alert('in');
e.preventDefault();
var obj = $(this);
...
I need to execute it after page load, as well as clicking on the link with class=”expand2″.
How would i simulate a click event right after the page load for the first on the form with a class “expand2”??
I’ve tried this:
$(function(){
$('.expand2:first').click();
}
didn’t work.
$(document).ready(function() { ... })is just shorthand for$(function() { ... })so that shouldn’t be your problem. Provided you’ve copied the code correctly, it just looks as though you forgot to close your bracketsEDIT: roXon’s demo with $(function(){}) just to show you it works the same
http://jsfiddle.net/rWbUD/1/