It's not a bug, is() always returns true for unsupported selectors.
Complex selectors like you're using are not supported.
And you can't do that with the :even or :odd pseudo-selectors, as $
(this) gives you a single element which is always "even".
$(".stripe tr").click( function(){
if($(this).is(".stripe tr:even")) // it's always even here, because
it's a single element (this)
$(this).css("background","green");
else
$(this).css("background","red");});
});
You have to understand that :even is a selector, not a 'property' or
'state' of the element. You could check that for yourself:
$('.stripe tr').click(function(){
if ( $('.stripe tr').index(this) % 2 ) {
//odd
} else {
//even
}
});
or resort to a more common way:
$('.stripe tr')
.filter(':even').click(function(){
$(this).css("background","green");
}).end()
.filter(':odd').click(function(){
$(this).css("background","red");
});
Try asking for help at http://groups.google.com/group/jquery-en/
before assuming things are buggy :)
cheers,
- ricardo
On Jan 15, 5:26 am, seekarmor <[email protected]> wrote:
> I want to make such effect as
> when click even table row,it's background will turn green.
> when click odd table row,it's background will turn red.
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <script src="http://code.jquery.com/jquery-latest.js"></script>
>
> <script>
> $(document).ready(function(){
>
> $(".stripe tr").click(
>
> function(){
> if($(this).is(".stripe tr:even"))
> $(this).css("background","green");
> else
> $(this).css("background","red");});
> });
> </script>
>
> </head>
> <body>
>
> <table class="stripe" width="50%" border="0" cellspacing="0"
> cellpadding="0">
>
> <thead>
> <tr>
> <th>name</th>
> <th>age</th>
> <th>QQ</th>
> <th>Email</th>
> </tr>
> </thead>
> <tbody>
> <tr>
> <td><a href="http://www.google.cn" >goolge</a></td>
> <td>cssrain</td>
> <td>demo</td>
> <td>toggleClass</td>
> </tr>
> <tr>
> <td>demo</td>
> <td>23</td>
> <td>31540205</td>
> <td>[email protected]</td>
> </tr>
> <tr>
> <td>demo</td>
> <td>23</td>
> <td>31540205</td>
> <td>[email protected]</td>
> </tr>
> </tbody>
> </table>
> </body>
> </html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---