HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="jQuery/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="js/script1.js" type="text/javascript"></script>
</head>
<body>
<div>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</div>
</body>
</html>
Script which works:
$(document).ready(function () {
$('li:nth-child(2)').fadeOut('fast');
});
Now I just use a variable to do the same thing and it does not work anymore.
var $var = $('li:nth-child(2)');
$(document).ready(function () {
$var.fadeOut('fast');
});
Can anyone please tell me the correct syntax. I have just started learning jQuery and know it is probably a simple mistake but I just cannot figure it out. Thanks in Advance. :)