views:

71

answers:

3

I want to select an element based on it's class and id, I have seen many similar questions on SO. Most of the users ask why would you ever want to do this - which is not very helpful, trust me, this is the simplest way of solving my UI problem, and it's a very unique and intereting UI related to making generic triple stores easily browsable.

At the moment the jQUery looks like this:

$(document).ready( function() {
    $(".predicates").hide();
    $(".objects").hide();
        $("#subject").click(
        function() { 
            $("#predId, .predicates").toggle(); // this line
            }
        );

        $("#predId").click(
        function() { 
            $("#objId, .objects").toggle();
            }
        );
});

The line I am really interested in is this

$("#predId, .predicates").toggle();

how do I get the select to ensure that both #predId and .predicates are true, at the moment it seems that only one or the other has to be true. Is there something like an && operator?

+1  A: 

Have you tried filter?

$("#predId").filter('.predicated').toggle();
piquadrat
+1  A: 

You could use the Filter() function.

$("#predId").filter('.predicates").toggle();

This will get all with id of predId then take from those the ones with class of .predicates

Fermin
+4  A: 

Like this, no space, no comma:

$("#predId.predicates").toggle();

Without a space, you're saying apply the selector to the same element :)

Nick Craver