bah, forgot the API docs link for index():

http://www.jquery.com/api

On 11/29/06, Aaron Heimlich <[EMAIL PROTECTED]> wrote:

On 11/29/06, Brice Burgess <[EMAIL PROTECTED]> wrote:
>
> Is there a quick way to check if an element exists in a jQ object stack?
> It seems that .find(), .filter(), .is() all take CSS selectors
> (strings)?


I believe index() is what you're looking for. According to the API
docs[1], it takes an object and returns its index in the jQ stack or -1 if
the object can't be found.

So your code would be:

<p>aaa</p>
> <p>bbb</p>
> <p class="noinc">ccc</p>
> <p>ddd</p>
>
> <script type="text/javascript">
> $().ready(function() {
>     var row = $('p');
>     var fRow = $(row);
>     fRow.not ('.noinc');
>
>     row.each(function(i) {
>
           if (fRow.index(this) >= 0) // my changes are here;

>             // element is in fRow , do Something!
>         else
>             // element is NOT in fRow, do Something else!
>     });
> });
> </script>
>

Although now that I think about it, you could probably do (untested)

row.each(function(i) {
  if($(this).is('.noinc')) {
    // do something
  } else {
    // do something else
  }
});

or

row.each(function(i) {
  if(jQuery.class.has(this, 'noinc')) {
    // do something
  } else {
    // do something else
  }
});

--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com




--
Aaron Heimlich
Web Developer
[EMAIL PROTECTED]
http://aheimlich.freepgs.com
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to