You're probably trying to access the elements before they exist in the dom. The way to do this is to listen for the window.onload
, or document.ready
events. jQuery makes this very easy as the standard factory method can take a function to automatically bind to the document.ready
event:
jQuery(function($){});
This has an added bonus that it can be used to alias jQuery
to $
to allow for the compatibility of using $
while not having to worry about noConflict
.
jQuery(function($){
alert($('#myTableHeader1').width());
alert($('#myTableHeader1').outerWidth());
alert($('#myTableHeader1').innerWidth());
});
You would do well to start using console.log
instead of alert
as you can use firebug or the built-in console in opera or chrome.
to use console.log you should check that console
exists:
if (window.console)
{
console.log(
$('#myTableHeader1').width(),
$('#myTableHeader1').outerWidth(),
$('#myTableHeader1').outerWidth()
);
}
This may or may not be the solution you're looking for. To tell you'll need to post the HTML along with the JavaScript. It may be as simple as a misspelling, or bad html syntax.