Jump to content

$ is undefined


The Little Guy

Recommended Posts

I have this:

var jsLive = {
   // some stuff
   item : function(){
      // some more stuff
   }
}
window.jsLive = $ = window.document.$ = window.$ = jsLive;

 

if I use this:

$.item();

 

The code will work in Chrome/Firefox, but I get an error in IE saying "$" is undefined. What can I do to fix it?

Link to comment
https://forums.phpfreaks.com/topic/226392-is-undefined/
Share on other sites

Here one of the pages:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
	<title></title> 
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
	<link rel="stylesheet" href="../style.css" /> 
	<script type="text/javascript" src="../../live/jsLive.js"></script> 
</head> 
<body onmousemove="$.item('#pos').innerHTML = $.mouseX()+ ', '+$.mouseY();">
	<div class="content">
		<h1>Miscellaneous</h1>
		<h2>Mouse X, Y Position</h2>
		<div id="pos">0, 0</div>
	</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/226392-is-undefined/#findComment-1168599
Share on other sites

If you move the mouse on the page before jsLive.js has been loaded then you'll trigger an error.

 

Bind to the onmousemove event only after everything's been loaded. You can add a script at the end of the page that adds the event listener rather that code it inline into the HTML.

Link to comment
https://forums.phpfreaks.com/topic/226392-is-undefined/#findComment-1168617
Share on other sites

That is just an example page.

 

I want to know how to get this to work in IE.

 

Here are other examples that don't work in IE:

<p>
<a href="http://google.com" class="google" id="mylink">Google.com</a>
</p>
URL: <input type="text" id="url" /><br />
<input type="button" value="Change" onclick="$.item('#mylink').attr('href', $.item('#url').value);" />

 

<p>
<input type="button" value="Load Ajax" onclick="$.query({
url :'./calls/html.html',
returnTo : '#loadHTMLAjax'});" />
</p>
<div id="loadHTMLAjax">
HTML returned data will display here
</div>

Link to comment
https://forums.phpfreaks.com/topic/226392-is-undefined/#findComment-1168621
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.