I have the following function that I want to run on page load and re-run when you click div#trigger. When you click div#trigger everything is fine. However on page load the code appears to sometimes work but sometimes indent the the wrong amount, and the alert (which i just put in there for debugging purposes) never fires. Thanks
function textIndentFunc () {
textString = $('#from-1 :selected').text();
$('#hidden').text(textString);
textWidth = $('#hidden').width();
inputWidth = $('#from-1 select').width();
indentMy = (inputWidth / 2) - (textWidth / 2);
$('#from-1').css('text-indent',indentMy);
}
$('#trigger').click(function(){
textIndentFunc();
alert('fire');
});
textIndentFunc();
UPDATE - I should have mentioned this code runs on document.ready.
UPDATE - moving the code to window.load doesn't change anything.