Bug Tracker

Modify

Ticket #986 (closed bug: fixed)

Opened 6 years ago

Last modified 6 years ago

jQuery("#IDParent #IDChild") throws error when #IDParent does not exists.

Reported by: alexo Owned by:
Priority: major Milestone: 1.1.3
Component: core Version: 1.1.1
Keywords: id selector error Cc: alex.objelean@…
Blocking: Blocked by:

Description

This bug was reproduced using "jQuery-1.1.1" version. I have the following code.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Untitled Document</title>
		<script type="text/javascript" src="lib/jquery/jquery-1.1.1.js"></script>
		<script>
    		jQuery(document).ready(function() {
                jQuery("#IDParent #IDChild").css("background", "red");                                			
            });
            jQuery.noConflict();
		</script>		
	</head>
	<body>	  
          <div id="IDParent">
            <div id="IDChild" class="menuClass">Text</div>
          </div>     		
	</body>
</html>

If instead of

          <div id="IDParent">...</div>  

you change the ID to something else (different from id used in the query), for instance:

          <div id="AnotherIDParent">...</div>  

the same query throws the following error at line 954.

 if ( m[1] == "#" && ret[ret.length-1].getElementById ) {

I know that the above query could be fixed this way:

  jQuery("#IDParent").find(#IDChild").css("background", "red"); 

still, it would be nice if the original code would work the same way.

Thank you!

Alex.

Change History

comment:1 Changed 6 years ago by aercolino

the above query could be fixed this way

means

the above query could be made fail quietly this way

comment:2 Changed 6 years ago by john

  • Priority changed from minor to major
  • Milestone set to 1.1.2

Added a test case for this in rev [1405].

comment:3 Changed 6 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in SVN rev [1573].

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.