jQuery: The Write Less, Do More JavaScript Library

Ticket #750 (closed bug: wontfix)

Opened 2 years ago

Last modified 1 year ago

jQuery( 'param', $( 'object' )[0] ); fails if an OBJECT element exists

Reported by: Andrea Ercolino Assigned to: anonymous
Type: bug Priority: minor
Milestone: 1.1.2 Component: core
Version: 1.1.1 Keywords: constructor
Cc: Needs:

Description (last modified by john) (diff)

Cause: getElementsByTagName( 'object' ) returns an array of functions, but jQuery() does not take care of it

Fix:

  // If so, execute it in context
 - if ( fn && typeof fn == "function" )
 + if ( fn && typeof fn == "function" && fn.nodeType == undefined )
    this.each(fn);

Attachments

Change History

Changed 2 years ago by joern

I can confirm this, though the problem lies now somewhere else. The quoted code was removed from jQuery(), but the problem is still there. I added a few assertions to show it.

Changed 2 years ago by andrea

I've tried the fix I suggested, and it worked.

It seems that it's a JavaScript issue (it's what Firebug shows, and in IE the problem is there too): getElementsByTagName( 'object' ) returns an array of functions. They are not functions, they are just DOM elements with a function type instead of an object type. All the OBJECT's properties are there, and I couldn't find more differences except the type.

Changed 2 years ago by joern

  • status changed from new to closed
  • resolution set to fixed

Actually my test was wrong, it works fine with the latest revision.

The code you quote doesn't exist anymore in jQuery, therefore can't cause any more harm.

Changed 2 years ago by joern

  • status changed from closed to reopened
  • resolution deleted

Works for FF, but still fails in IE.

Changed 2 years ago by joern

  • status changed from reopened to closed
  • resolution set to fixed

Fixed.

Changed 2 years ago by andrea

  • status changed from closed to reopened
  • resolution deleted

OBJECT.getElementsByTagName("*") and OBJECT.all return no elements

This is the IE7 bug this one is related to. I've posted a long message with details and a fix in the dev list.

Changed 2 years ago by john

  • status changed from reopened to closed
  • version set to 1.1a
  • resolution set to fixed

Fixed in SVN rev 994. I just added a check enforcing all "*" searches to be converted into "param". This isn't fully optimal, but at least its consistent cross-platform now.

Changed 2 years ago by andrea

Will it fail on a markup like this ? (http://www.w3.org/TR/html401/struct/objects.html)

<P>                 <!-- First, try the Python applet -->
<OBJECT title="The Earth as seen from space"
        classid="http://www.observer.mars/TheEarth.py">
                    <!-- Else, try the MPEG video -->
  <OBJECT data="TheEarth.mpeg" type="application/mpeg">
                    <!-- Else, try the GIF image -->
    <OBJECT data="TheEarth.gif" type="image/gif">
                    <!-- Else render the text -->
     The <STRONG>Earth</STRONG> as seen from space.
    </OBJECT>
  </OBJECT>
</OBJECT>

Changed 2 years ago by andrea

  • status changed from closed to reopened
  • resolution deleted

I've retouched my fix, following John's style. It's just 89 packed bytes fatter, and should work fine with the above 'official' example.

jQuery.getElementsByTagName declaration:

getElementsByTagName: function( e, t, rec ) {
	t = t.toUpperCase();
	if( rec !== false ) rec = true;
	var r = [];
	for ( var c = e.firstChild; c; c = c.nextSibling ) {
		if ( c.nodeType == 1 && ( c.nodeName == t || t == "*" ) )
			r.push( c );
		if( rec )
			r = r.concat( jQuery.getElementsByTagName( c, t ) );
	}
	return r;
},

First refactored chunk (children):

// Perform our own iteration and filter
for ( var i = 0, rl = ret.length; i < rl; i++ )
	r = r.concat( jQuery.getElementsByTagName( ret[i], m[1], false ) );

Second refactored chunk (descendants):

// Grab the tag name being searched for
var tag = m[1] != "" || m[0] == "" ? "*" : m[2];
// We need to find all descendant elements, it is more
// efficient to use getAll() when we are already further down
// the tree - we try to recognize that here
for ( var i = 0, rl = ret.length; i < rl; i++ )
	jQuery.merge( r,
		m[1] != "" && ret.length != 1 ?
			jQuery.getAll( ret[i], [], m[1], m[2], rec ) :
		// Handle IE7 being really dumb about <object>s
		ret[i].nodeName.toUpperCase() == "OBJECT" && tag == "*" ?
			jQuery.getElementsByTagName( ret[i], tag ) :
			ret[i].getElementsByTagName( tag )
	);

Changed 2 years ago by john

  • priority changed from major to minor
  • version deleted
  • milestone deleted

No, it won't fail on that markup, since you could do: $("object").find("object, strong")

Honestly, if you can show me a public web site that puts anything besides params inside of an object, I'll be more included to fix this. As it stands, you're still able to select descendant elements by type - and able to select all params using "*".

The biggest issue that I have with this fix is that it will significantly degrade the performance of select-by-tag queries.

Changed 2 years ago by andrea

You mean performance degradation strictly limited to selections that resolve to a call to OBJECT.getElementsByTagName("*")...

Changed 1 year ago by anonymous

World of Warcraft™ is a registred trademark of Blizzard Entertainment®. This site is in no way associated with or endorsed by Blizzard Entertainment®. Warcraftmovies.com graphics made by Balgosa Windspire(wow gold),(world of warcraft gold) ,(buy wow gold)

Changed 1 year ago by john

  • status changed from reopened to closed
  • version set to 1.1.1
  • resolution set to wontfix
  • description changed from Cause: getElementsByTagName( 'object' ) returns an array of functions, but jQuery() does not take care of it Fix: // If so, execute it in context - if ( fn && typeof fn == "function" ) + if ( fn && typeof fn == "function" && fn.nodeType == undefined ) this.each(fn); to Cause: getElementsByTagName( 'object' ) returns an array of functions, but jQuery() does not take care of it Fix: {{{ // If so, execute it in context - if ( fn && typeof fn == "function" ) + if ( fn && typeof fn == "function" && fn.nodeType == undefined ) this.each(fn); }}}
  • milestone set to 1.1.2

Ok, I'm moving this to being resolved - the current fix seems to solve the most-pressing issues related to this bug, without sacrificing any speed, or adding a significant amount of code.

I've also contacted the IE team - so they are aware of the issue, and are working to resolve it.

Changed 1 year ago by andyzzz

ativan diflucan ativan ativan celexa sonata ativan imitrex flomax ativan levitra levitra guaranteed cheapest online levitra com cialis levitra prescriptionscom viagra cialis levitra levitra clinical data cialis levitra sales viagra buy levitra online viagra cialis levitra levitra viagra buy levitra levitra softabs buy levitra online levitra online discount levitra order levitra levitra danger viagra cyalis levitra compared cialis compare levitra viagra which is better viagra cialis or levitra flonase levitra myonlinemeds biz nexium stimula nexium celebrex levitra nexium propecia renova valtrex viagra nexium side effects new yorker prilosec nexium between difference nexium prilosec nexium pharmacy paxil wiki levitra generic paxil paxil ultram lexapro paxil prozac zoloft paxil side effects prozac zoloft paxil zoloft versus paxil prozac vs paxil paxil vs zoloft paxil versus zoloft buspar celexa prozac paxil anafranil paxil withdrawal symptoms how to switch from paxil to celexa paxil zoloft between difference paxil zoloft paxil vs prozac depression celexa vs paxil prozac paxil paxil prozac vs zoloft or paxil zoloft paxil prozac prozac interactions with viagra cialis levitra ultram and prozac drug interaction prozac ultram prozac nation prozac side effects lexapro paxil prozac zoloft prozac zoloft paxil prozac vs paxil soma buy cialis levitra low online pharmacy price soma viagra drug interaction soma ultram drug soma akane soma buy soma soma mandal buy soma online prozac soma soma carisoprodol online prozac soma boards chongqed carisoprodol generic soma viagra cialis phentermine soma carisoprodol soma soma pharmacy buy cheap drugs lipitor tricor cardizem soma soma prozac soma online zoloft levitra lipitor online pharmacy pharmacy zoloft phentermine levitra low price pharmacy zoloft phentermine viagra ultram zoloft zoloft ultram zoloft ultram interaction zoloft side effects zoloft litigation weight, zoloft vs. lexapro zoloft versus lexapro lexapro zoloft zoloft and lexapro zoloft vs lexapro zoloft lexapro side effects lexapro versus zoloft zoloft lexapro comparison lexapro vs. zoloft changing from zoloft to lexapro weight gain more zoloft or lexapro which is better for anxiety lexapro or zoloft lexapro paxil prozac zoloft zyrtec levitra myonlinemeds biz vaniqa zyrtec myonlinemeds biz ultram ultram zyrtec 2737 aid amerimedrx com ultram zyrtec allegra claritin zyrtec claritin allegra zyrtec zyrtec cetirizine hcl lots of allergies just one zyrteco zyrtec clartin allegra zyrtec and allegra used together zyrtec and allegra combined combining allegra with zyrtec to treat hives zyrtec vs allegra myonlinemeds biz nexium zyrtec allegra zyrtec zyrtec claritin claritin zyrtec allegra vs zyrtec zyrtec and allegra zyrtec zantac error zyrtec side effects carisoprodol valium zyrtec

Note: See TracTickets for help on using tickets.