diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index cc5ca841c52f6e30ee1284a13741db63972f39c1..f111551cc51106ca3b85e4e913cec12ccb94a331 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -383,7 +383,7 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0)
 
 	$out= "\n<!-- Ajax code to switch constant ".$code." -->".'
 	<script type="text/javascript">
-		$(function() {
+		$(document).ready(function() {
 			var input = '.json_encode($input).';
 			var url = \''.DOL_URL_ROOT.'/core/ajax/constantonoff.php\';
 			var code = \''.$code.'\';