Bug Tracker

Ticket #8021 (closed bug: duplicate)

Opened 4 years ago

Last modified 4 years ago

Possible regression: Finding elements doesn't work if context elements' id contains dot

Reported by: mikioma Owned by:
Priority: high Milestone: 1.5
Component: selector Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

The "$(css, context)" syntax to find elements inside the "context" element doesn't work on jQuery 1.4.4 if the context element's id contains a dot character.

It works on 1.4.2 though!!!

You can use this test page:

<html>
  <head>
  <script type="text/javascript" src="jquery-1.4.4.min.js"></script>
  <script type="text/javascript">
    function test()
    {
      var dotted = document.getElementById("Dotted.Id");
      var undotted = document.getElementById("UndottedId");
      alert($(".test", dotted).length + " vs " + $(".test", undotted).length);
    }
  </script>
  </head>
  <body id="body">
    <button type="text" onclick="test()">Press to test</button>
    <div id="Dotted.Id" style="border: 2px solid red">
      <p class="test">Test</p>
    </div>
    <div id="UndottedId" style="border: 2px solid black">
      <p class="test">Test</p>
    </div>
  </body>
</html>

When you press the button the "alert" displays "0 vs 1", stating it find 0 elements with class "test" inside "Dotted.Id" but one inside "UndottedId".

If you include "jquery-1.4.2-min.js" instead, it displays "1 vs 1", stating that it finds one result in each DIV, no matter its Id.

Change History

comment:1 Changed 4 years ago by jitter

  • Priority changed from undecided to high
  • Resolution set to duplicate
  • Status changed from new to closed
  • Component changed from unfiled to selector
  • Milestone changed from 1.next to 1.5

Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!

This is a known issue and already fixed in the jQuery 1.5b1 release. This  test case shows that it now works as expected again.

Check the ticket mentioned below for more information.


Also the next time please consider first searching the bug tracker if your issue hasn't already been filed, because there are like 15+ duplicates of this one already on the bug tracker.

comment:2 Changed 4 years ago by jitter

Duplicate of #7533.

Note: See TracTickets for help on using tickets.