Why doesn't IE8 like this JS? - javascript

IE8 has been throwing this error at me
SCRIPT65535: Unexpected call to method or property access.
load-scripts.php, line 4 character 25690
I removed a .js file from the code, and the error went away. I started commenting functions out, and narrowed it down to this one. With this one commented, I don't get the error. With it active, I do get it
$("title, .ab-item").each(function() {
var text = $(this).text();
text = text.replace("RepAgent", "Review Scout");
$(this).text(text);
});
I've used JSHint and it says that it's valid?

I'm pretty sure that Internet Explorer doesn't like you messing with <title> element contents. That's not really how you set the document title anyway; just set document.title.

jQuery uses appendChild inside $.text() .
Although <title/> has a appendChild-method(inherited from HTMLElement), this method may not be used.(it's also not listed in the title-methods)

Related

jQuery: Unrecognized Expression (getting around this error)

jQuery("input[name=a.b.c]")
Executing this line using jQuery 1.10.2 or 1.9.1 results in the message:
"Syntax error, unrecognized expression: input:hidden[name=a.b.c]".
I understand the core problem which is that the dots are not escaped or quoted out. This would work:
jQuery("input[name='a.b.c']")
The constraint is that I do not have the ability to change the line of code with the bad selector. That line is produced by the website (which I don't own) and they don't give me the ability to change that.
However, they do allow me to add arbitrary JS files to the header of the page (which means I can use a different jQuery version or even edit the jQuery file). My question is whether anyone knows another way around this so that jQuery can cope without the quotes since I cannot change the bad code.
For those saying that I can just change the name, this doesn't help because the JS still throws an error because changing the name of the element doesn't fix the bad selector.
Thanks
The proper way of executing this selector is:
jQuery('input[name="a.b.c"]')
Obviously you need to edit the algorithm that creates this line, there's no way jquery will accept an invalid selector.
Take a look here.
How do I extend jQuery's selector engine to warn me when a selector is not found?
In your case I would do something like this.
var oldInit = $.fn.init;
$.fn.init = function(selector, context, rootjQuery) {
selector = fixItWithQuotes(selector, context, rootjQuery);
return new oldInit(selector, context, rootjQuery);
};
untested by me, but it should give you an idea.
Also, this might give you more ideas?
http://blog.tallan.com/2012/01/17/customizing-the-default-jquery-selector-behavior/
Hope that makes sense.
Why don't you change the name attribute yourself?
var el = $("input");
el.attr("name", el.attr("name").replace(/[\d\.]+/g, ""));
console.log(el.attr("name"));
Then change it back if you need to. jsFiddle here

'target.html()' is null or not an object

I'm trying to replace all occurrences of a certain character (quotes) from an element. My code works fine in Chrome and FF but fails in IE with the debugger saying - 'target.html()' is null or not an object
here is what my code looks like -
text = "some random text";
target = $('#target');
target.append(text);
target.html(target.html().replace(/"/g, " "));
What's causing that error in IE and how do i fix it?
'target' is used an attribute and IE does not like it if you use it as a variable name. In fact it even refuses to recognize event.target and insists on event.srcElement (tell me about it ..) .
Anyways, it should work if you rename the object to $target.
One of the main reasons I get such errors is because the HTML is not correctly formed(and it sure gave me hell before I found out). Other browsers allow a missing '>' or other syntactical errors, but IE is very strict.
So just see minutely that the markup in target.html() is correct.

Uncaught TypeError: Cannot call method 'get' of null

I know there are many threads about this issue and i ve been looking for my specific case but i have not found anything relevant.
I am implementing this javascript cashRegister effect in this page but i get this error msg
"Uncaught TypeError: Cannot call method 'get' of null"
It points to the raw 18 of the plugin.js:
var current_value = this.element.get('text');
What might cause this error? What i should try to do now?
Thanks
I think your problem is at this line:
var total = $('total');
The selector total means "find elements with the name 'total'". What you really want is to find the element with the id of "total," so do this instead:
var total = $('#total');
Edit:
I think some of the confusion stems from the fact that the $ in the site you're referencing is the $ from MooTools. In your page, you are including jQuery, which has an entirely different $ object that behaves differently. I believe that $('total') is how you select an element by ID in MooTools.
I'm not sure how you can load both libraries without having naming conflicts, but if you can figure that out, make sure you're using MooTools to select the total instead of jQuery.
Edit 2:
After a bit of research (I'm unfamiliar with MooTools), I see that you could replace $('total') with:
document.id('total')

ie6/7 script tag population giving "unexpected call to method or property access"

I use AJAX to get the content of a script, and then use the following code:
var scr = document.createElement('script');
scr.appendChild(document.createTextNode(script)); // ***
document.getElementsByTagName('head')[0].appendChild(scr);
Where script is astring populated from AJAX. This works fine in IE9, Chrome and Firefox. However, in IE6 and 7 I get an error:
Unexpected call to method or property access
IE gives the number of the the line indicated with the // ***.
Although there are multiple other questions about this, none of the appear to address this precise issue.
Older IE's do not accept child nodes in script elements ( or in style and option elements, but that's another two questions).
You can set the script element's text property instead.
(scripttext is a string of, well, script text.)
var scr = document.createElement('script');
if(window.addEventListener)scr.appendChild(document.createTextNode(script))
else scr.text=scripttext;
document.getElementsByTagName('head')[0].appendChild(scr);
If you already have the code in a string, why make a script tag out of it? Can't you just call eval(script) on it. Won't that do the same thing?
document.getElementsByTagName('head')[0]*;*.appendChild(scr);
Why did you put a semicolon here?

JQuery issue (major) with IE - all versions

This only happens with IE (all versions), on line 1120 in
jquery-1.2.6.js I get the following error:
Line 1120:
Invalid Property Value
The line in the js file is the following:
elem[name] = value;
It is inside attr: function( elem, name, value )
Does anybody have a problem similar to this?
If this is also you, it sounds like you're trying to change the CSS of the element rather than give it an attribute.
If that is the case then try this instead;
jQuery.css('color', 'inherit');
This error can also occur if you call jQuery.css with an invalid attribute value, such as:
$('div.foo').css('padding-left', 'NaNpx');
The problem is IE-only because you are probably trying to set something like "min-height" which exists in (a proper CSS implenting) browser like Firefox, but not in a (demon spawned fiend of a) browser like Internet Explorer. I ran in to the same issue using jQuery's own dialog UI function.
I was a huge proponent of jQuery before this, but this has really put some egg on its face.

Categories