Here’s a contrived example of my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
<title></title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href=".css"/>
</head>
<body>
<div>
<a href="http://www.google.com" class="foo">YahOO</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$("document").ready(function() {
$("#foo").trigger('click');
});
</script>
</body>
</html>
I would like to have the link fired immediately upon page load. The above does not work and is incorrect? How could this be done?
You have the class
fooset on your element, not anidso you need to use.foo. Also, as @JusticeErolin pointed out, the document ready handler doesn’t need quotes. Try this:For reference,
$("#foo")will look for an element withid="foo", of which there should only ever be one in your page as ids should be unique.$(".foo")will look for elements withclass="foo", of which you can have as many as you like.