Bug Tracker

Modify

Ticket #5469 (closed bug: worksforme)

Opened 4 years ago

Last modified 4 years ago

Class selector doesn't work as expected when specifying top

Reported by: fforw Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

var $tst =  $("#tst");
$(".foo span", $tst)

does not find the span on this HTML

<div id="tst" class="foo">
	<span>xxx</span>
</div>

I can understand and would expect that code not to regard a ".foo" outside of $tst. But shouldn't it regard the .foo on $tst ?

Attachments

select.html Download (713 bytes) - added by fforw 4 years ago.
Test page
select.2.html Download (753 bytes) - added by fforw 4 years ago.
same test using find, not working either..

Change History

Changed 4 years ago by fforw

Test page

comment:1 Changed 4 years ago by dmethvin

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

$(y,x) is the same as $(x).find(y), so no. It's best to ask these questions on the forums rather than the bug tracker.

comment:2 Changed 4 years ago by fforw

  • Status changed from closed to reopened
  • Resolution worksforme deleted

It is *not* working. And it doesn't work with .find() either.

comment:3 Changed 4 years ago by fforw

If you think that is the best and least suprising solution this way and intended behaviour, at least document it as such.

Changed 4 years ago by fforw

same test using find, not working either..

comment:4 Changed 4 years ago by dmethvin

  • Status changed from reopened to closed
  • Resolution set to worksforme

It is *not* working. And it doesn't work with .find() either.

That's because you have misunderstood the .find() method, which finds *descendant* elements. Your #tst element is not a descendant of itself.

at least document it as such.

 http://docs.jquery.com/Traversing/find#expr

"Searches for descendent elements that match the specified expression."

comment:5 Changed 4 years ago by fforw

The SPAN element I am searching is a descendent.

comment:6 Changed 4 years ago by fforw

I never expected the context itself to be found. I was always searching an descendent. I just expected the context to be regard when looking for the class.

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.