Object Expected Error In Prototype.js
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up element = $(element); Object expected error? up vote 0 down vote favorite on a webpage in under developmnt i'm getting this error on IE element = $(element); this code is in prototype.js Object expected How to get rid of this error. Update: jQuery is also being used on site. javascript jquery xhtml prototypejs share|improve this question edited Dec 29 '11 at 15:57 Rob W 205k32470462 asked Mar 4 '10 at 7:47 Jitendra Vyas 43.3k152447729 you need to show your code. –Sarfraz Mar 4 '10 at 7:49 Please give more details ,then only i can get you well. –Vibin Jith Mar 4 '10 at 7:49 What is element before this line? –kennytm Mar 4 '10 at 7:51 I'm 99% sure (until you post more code) that your $(element) is either undefined, or you're setting some unsupported value. –Adam Kiss Mar 4 '10 at 7:53 @Adam Kiss: that's what it is. –Sarfraz Mar 4 '10 at 7:55 | show 1 more comment 3 Answers 3 active oldest votes up vote 3 down vote Is "element" the id of your element? If so try making it element = $("element") share|improve this answer answered Mar 4 '10 at 7:53 Tim Goodman 11.4k43759 add a comment| up vote 2 down vote your statement should be element = $("id of element") suppose you have the following code.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up IE8 http://stackoverflow.com/questions/2377605/element-element-object-expected-error returns 'Object expected' prototype up vote 2 down vote favorite I have this code, that works good on all browser and IE9> , but in IE8 it throws me JScript Object Expected on the first line (Array.prototype...) this.items = Array.prototype.slice.call( document.querySelectorAll( '#' + this.el.id + ' > li' ) ); this.itemsCount = this.items.length; this.itemsRenderedCount = 0; this.didScroll = false; I tried changing document.querySelectorAll( '#' http://stackoverflow.com/questions/20977832/ie8-returns-object-expected-prototype + this.el.id + ' > li' ) to $(this).attr("id") - same error. But when i change this line to simple jquery picker , for example $("#someId") , it works fine. Ideas anyone? javascript internet-explorer-8 share|improve this question asked Jan 7 '14 at 17:17 user3170124 As both QSA (with CSS2 selectors only) and slice is supported in IE8, it's probably the wrong selector and no element is returned. –adeneo Jan 7 '14 at 17:20 what does console.log('#' + this.el.id + ' > li') output –Prisoner Jan 7 '14 at 17:24 I checked it , all the elements exist (console log returns: #scroll-fade-effect1 > li #scroll-fade-effect2 > li #scroll-fade-effect3 > li #scroll-fade-effect4 > li –user3170124 Jan 7 '14 at 17:35 It'll never make any difference if the elements exist or not. A collection will always be returned. –cookie monster Jan 7 '14 at 17:37 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted This is because IE8 and lower requires a native object as the this value of built-in Array methods. The collection you're passing is a hos
try { // try using .slice() return Array.prototype.slice.call(arr); } catch(e) { // otherwise, https://recalll.co/app/?q=javascript%20-%20IE8%20returns%20'Object%20expected'%20prototype manually create the array var result = []; for (var i = 0; i < arr.length; ++i) result.push(arr[i]); return result; } } this.items = _slice( document.querySelectorAll( '#' + this.el.id + ' > li' ) ); Side note, since this.el must be a ul or ol element, and so its children must object expected be li elements, why not just do this? this.items = _slice( this.el.children ); Works like a charm, thank you javascript - IE8 returns 'Object expected' prototype - Stack Overflow View More at http://stackoverflow.com/questions/20977832/ie8-returns-object-ex... The console object is not defined in IE8: javascript - IE8 Object expected error - Stack Overflow View More object expected error at http://stackoverflow.com/questions/18761119/ie8-object-expected-e... Turns out Internet Explorer chokes if you use anything other than "javascript" in the language attribute of the script tag. I was using version numbers appended onto javascript in the language attribute, which was causing IE not to load prototype.js. internet explorer - 'Object Expected' Javascript error in IE8 when usi... View More at http://stackoverflow.com/questions/949431/object-expected-javascr... Are you sure that this: $("icImgDiv" + icAlternate()) returns a reference to an element? If so, have you tried using Microsoft Script Debugger / Visual Studio to debug when and where the exception is raised? internet explorer - 'Object Expected' Javascript error in IE8 when usi... View More at http://stackoverflow.com/questions/949431/object-expected-javascr... Also check that the script tag's type is "text/javascript". I had this error in IE8, and fixed it by changing the type= part of the script tag from "application/javascript" to "text/javascript". internet explorer - 'Object Expected' Javascript error in IE8 when usi... View More at