4

Imagine some HTML code :

<div class="container">  
   <div class="first">
     <a class="result"> </a> 
   </div>

   <div class="second">
      <a class="result"> </a> 
  </div>
</div>

and

$("a.result:first").parent().select('a');

As I think it must return a in div.first, right?

Because when I do this logic in CsQuery it's return a in div.first and div.second.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
nazarkin659
  • 503
  • 3
  • 11
  • What exactly are you trying to do? – Dom Apr 09 '13 at 22:36
  • 1
    The jQuery [`.select` function](http://api.jquery.com/select/) expects a function as argument. What are you trying to do? – Felix Kling Apr 09 '13 at 22:37
  • 2
    Maybe you should use [`find`](http://api.jquery.com/select/) instead of `select`. – Elias Zamaria Apr 09 '13 at 22:38
  • I guess it would be helpful if you post the exact csquery function call you are using. – Felix Kling Apr 09 '13 at 22:44
  • 1
    It seems to be working http://jsfiddle.net/arunpjohny/BRDqV/ – Arun P Johny Apr 09 '13 at 22:46
  • 1
    I think you have to primarily clarify one thing: Is your issue with jQuery or CsQuery? – Felix Kling Apr 09 '13 at 23:02
  • I using CsQuery. The problem is - if I use this selector in CsQuery $("a.result:first").parent().select('a') it's return me both of a. But, if I will create new instance of CsQuery before use function "select", it's return me only first a. for example: new CQ($("a.result:first").parent().RenderSelection()).Select('a'); I tried debug that in source code and find out that if I use first variant new CQ inherit previous selection (it's clearly normal), but why then when I trying to find smt it's search in ALL document?... – nazarkin659 Apr 10 '13 at 19:06
  • in CsQuery `Select` operates against the whole DOM, so `$("a.result:first").parent().select('a')` (if it were valid C# code) would be the same as `$('a')`. Perhaps what you want is `$("a.result:first").parent().find('a')`. The `find` method (in both CsQuery and jQuery) searches the children of the selected elements, and not the entire DOM. – Jamie Treworgy Apr 10 '13 at 19:24
  • Is it correct that function "select" in CsQuery working like that? if yes, when I can use it? Because I don't understand that... – nazarkin659 Apr 10 '13 at 19:39
  • @user2263827 Jamie is the author and lead developer of CsQuery. If he said that's the way it acts that's the way it acts. CsQuery is open source and the source code is very readable, you're more than welcome to have a peek – Benjamin Gruenbaum Apr 12 '13 at 13:11

1 Answers1

2

This would be sufficient :

$("a.result:first")   // will return a in div.first

.parent().select('a') seem's to be unnecessary.

Fiddle

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111