0

Let us suppose that we have a div element #a-node and a javascript method create one or more other div's called .b-node (not need inside this first) and it too add an #a-node class .b-node-enabled.

Exists a way to toggle/turn on the .b-node-enabled only if exists .b-node's connected specifically to #a-node?

Example:

  • If no one .b-node is connected with #a-node, so turn class off;
  • If one or more .b-node is connected with #a-node, so turn class on;

I can use jQuery, if need and -webkit features.

REAL PROBLEM

I have a div popup that create a background, and I need turn on a classe on the main content body (that not inside this popup, and vice-versa, just appended to body too), and I can have more than one popup enabled at same time. I only need turn off the .b-node-enabled if no one popup is showing.

<body>
    <!-- MAIN CONTENT -->
    <div id="a-node" class="b-node-enabled">...</div>
    <!-- POPUPS -->
    <div class="b-node">...</div>
    <div class="b-node">...</div>
    <div class="b-node">...</div>
</body>
2
  • Your question could use some clarification. If I get it, you need #a-node to get the class .b-node-enabled if there is any popup, is that correct? Do you have access to display and hide pop-up events? And third, how can you tell whether a pop-up is being displayed? Commented Mar 6, 2013 at 14:11
  • 1. Exactly; 2. I create the popup, so I have full control. 3. I create it with a class that I write. Commented Mar 6, 2013 at 14:14

1 Answer 1

2

I don't know if I really understood your question, but maybe this code snippet can help you (jQuery needed).

function updateANodeClass() {
    if ($(".b-node").length) {
        $("#a-node").addClass("b-node-enabled");
    } else {
        $("#a-node").removeClass("b-node-enabled");
    }
}

After you've added or removed one .b-node you'll have to call that function to update the class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.