I have a simple page, just trying to attach a load event to the document. I am not sure which event handler to use in jQuery to do this with. I tried $()
and $(document).ready
and .load
but neither seem to run the code at the right time. Should I be using .on
, .live
? Or is there something I am doing wrong. Here is a sample:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
$(document).ready(
showWidth()
);
function showWidth() {
alert($('#textTitle').width());
}
</script>
</head>
<body>
<div class="page">
<div id="title">
<h1 id="textTitle">yo</h1>
</div>
</div>
</body>
</html>
When I run this the alert displays null
.