Sweetz
Sweetz

Reputation: 342

Execute a function when page is loaded

$(window).bind("load", function() {
   $("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});

Hi how do i execute this function as soon as the page is loaded?? This function is being called only when i refresh the page, but i want it to be called when ever the page is loaded.

Upvotes: 0

Views: 130

Answers (5)

FrontEnd Expert
FrontEnd Expert

Reputation: 5813

$(document).ready(function(){
   //Write your code 
});

Put Scripts at the Bottom

The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames. In some situations it's not easy to move scripts to the bottom. If, for example, the script uses document.write to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to workaround these situations. An alternative suggestion that often comes up is to use deferred scripts. The DEFER attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. Unfortunately, Firefox doesn't support the DEFER attribute. In Internet Explorer, the script may be deferred, but not as much as desired. If a script can be deferred, it can also be moved to the bottom of the page. That will make your web pages load faster.

http://developer.yahoo.com/performance/rules.html#js_bottom

Upvotes: 0

Vond Ritz
Vond Ritz

Reputation: 2012

$(document).ready(function(){
   //execute ur code here.
});

Upvotes: 2

griegs
griegs

Reputation: 22770

using jQuery you could use;

$(function(){
//Your code here
});

Upvotes: 1

Techie
Techie

Reputation: 45124

Try the code below

$(document).ready(function() {
  // Handler for .ready() called.
  $("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});

OR

$(function() {
     // Handler for .ready() called.
     $("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
    });

.ready() - Specify a function to execute when the DOM is fully loaded.

jQuery Document Ready Explained

Upvotes: 1

GautamD31
GautamD31

Reputation: 28763

Like this by using document.ready

$(document).ready(function(){     
    $("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important');
});

or you can use $(function) like

$(function(){
    $("#placeholder .flot-text .xAxis .tickLabel").css('height','90px','important'); 
});

Upvotes: 5

Related Questions