DomingoSL
DomingoSL

Reputation: 15504

Two "$(document).ready(function()" on the same page cause problems, how to handle?

i have a web page with a fix header included by a simple include("header.php"), in this header i have a jquery function that begins with: $(document).ready(function() {. One of my pages, need to have another jquery function on the body, if i put two times in the same page the function $(document).ready(function() { one of them stop to work. How can i handle this?, as you can see i cant put the scripts on the same position because one have to be always on the header and the other one appear only in some pages. Thanks!

Upvotes: 0

Views: 1383

Answers (1)

Guffa
Guffa

Reputation: 700680

jQuery handles multiple event handlers, so there is nothing that keeps you from having multiple ready event handlers.

Demo: http://jsfiddle.net/VysPB/

There has to be something inside the event handlers that keeps them from working in the same page.

Upvotes: 2

Related Questions