<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
var mySite={};
mySite.title=$('h1');
mySite.makeRed= function(){
return mySite.title.css('color','red');
};
$(document).ready(function() {
mySite.makeRed();
});
</script>
Good day. Why does the method called inside the function doesn't return anything?
mySite.title=$('h1');will not select theh1element at this time, because the DOM is not ready. It must be inside a$(document).ready()handler to be able to select that element.