jquery-urlinternal icon indicating copy to clipboard operation
jquery-urlinternal copied to clipboard

IE says "method not found" on A=(z||"").match

Open stuffmc opened this issue 15 years ago • 7 comments

This piece of code: A=(z||"").match

It looks like IE doesn't like z||"" - I replaced with just "" for ex. and it doesn't complain. Obviously we need another solution :)

stuffmc avatar Jan 08 '10 23:01 stuffmc

Can you show me where in your code this is occurring? I've never encountered this error.

cowboy avatar Jan 09 '10 00:01 cowboy

It's a mix of jQuery and Prototype (in rails) so maybe I need to take the "content" of element explicitely. Here is where I use the isUrlInternal

initialize: function(){ 
    $$('div#content').first().observe('click', (function(event) { this.get_hash(event); } ).bind(this) );
},

get_hash: function(event) {
    itself = event.element().tagName == 'A';
    itsparent = event.element().parentNode.tagName == 'A';
    itsparentsparent = event.element().parentNode.parentNode.tagName == 'A';
    if ( (itself || itsparent || itsparentsparent)) {
        var element = (itself) ? event.element() : ( (itsparent) ? event.element().parentNode : event.element().parentNode.parentNode);
        if (jQuery.isUrlInternal(element)) {

and this is where IE complains that "element" does not have the method "match" I think

stuffmc avatar Jan 09 '10 08:01 stuffmc

Take a look at the documentation, and you'll see that jQuery.isUrlInternal() expects a url as its argument, not an element.

Of course, you can use something like this if you really want: if ( jQuery(element).urlInternal().length ) { ... }

cowboy avatar Jan 09 '10 13:01 cowboy

element.href

cowboy avatar Jan 09 '10 13:01 cowboy

oh. crap. sorry. I feel very stupid. closing this one.

stuffmc avatar Jan 09 '10 13:01 stuffmc

Only IE complains though. So how should I send the URL of the element?

stuffmc avatar Jan 09 '10 13:01 stuffmc

The method expects a string. So if you're not specifying a string, but browsers are not complaining, they may be casting your value into a string. IE might not be doing that.

Pass in a string!

cowboy avatar Jan 09 '10 14:01 cowboy