Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6813595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:35:19+00:00 2026-05-26T20:35:19+00:00

I want to display either OPEN or CLOSED, depending on the conditional, in the

  • 0

I want to display either “OPEN” or “CLOSED”, depending on the conditional, in the parent, but I don’t know how to do this. This code makes two <h2> headings work as a drop down list. I want the function to pass the parameters, and if it does not equal 1, I want to display OPEN in the <span> of the <h2>.

Javascript

<script type="text/javascript">
    var a = null;
    var b = null;
    var c = 1;
    $(document).ready(function () {
        $(".toggle_container").hide();
        $("h2.trigger").click(function () {
            $(this).toggleClass("active").next().slideToggle("slow");
        });
    });
    function divide(a, b) {
        (a / b != c) ?
      // Where help is needed
      //  $(this).parent(".status").text("OPEN").css("color", "green") :
      //  $("team").parent(".status").text("CLOSED").css("color","red");
        document.write(a + " / " + b);
    }
</script>

HTML

 <body>
    <div class="tournaments">
    <h2 class="trigger">Tournament 1<span class="status"></span></h2>
        <div class="toggle_container">
            <div class="block">
                <h3>Details</h3>
                <p>Deadline: DATE</p>
                <p>Teams: <span class="team"><script type="text/javascript">divide(3, 7)</script></span>
                </p>
            </div>

        </div>
        <h2 class="trigger">Tournament 2 <span class="status"></span></h2>
        <div class="toggle_container">
            <div class="block">
                <h3>Details</h3>
                <p>Deadline: DATE</p>
                <p>Teams: <span class="team"><script type="text/javascript">divide(3,7)</script></span>
                </p>
            </div>
        </div>
    </div>
</body>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:35:19+00:00Added an answer on May 26, 2026 at 8:35 pm

    When you execute a JavaScript function in HTML the way you’re doing, that function has no awareness of what HTML element contains it. One way to bypass that problem (my favorite way) is to put those variables in data- attributes for the DOM element, and use jQuery to extract and operate on them using .data().

    Your second problem is that the h2 tag isn’t a parent (container) of the span.team element. A little more DOM traversal is necessary to get to the one from the other.

    http://jsfiddle.net/mblase75/fzwBM/

    new HTML:

    <div class="tournaments">
        <h2 class="trigger">Tournament 1<span class="status"></span></h2>
        <div class="toggle_container">
            <div class="block">
                <h3>Details</h3>
                <p>Deadline: DATE</p>
                <p>Teams: <span class="team" data-a="3" data-b="7"></span>
                </p>
            </div>
        </div>
    
        <h2 class="trigger">Tournament 2 <span class="status"></span></h2>
        <div class="toggle_container">
            <div class="block">
                <h3>Details</h3>
                <p>Deadline: DATE</p>
                <p>Teams: <span class="team" data-a="3" data-b="7"></span>
                </p>
            </div>
        </div>
    </div>
    

    new JS:

    $(document).ready(function() {
        $(".toggle_container").hide();
        $("h2.trigger").click(function() {
            $(this).toggleClass("active").next().slideToggle("slow");
        });
    
        $('span.team').each(function() {
            var a = $(this).data('a');
            var b = $(this).data('b');
            var $status = $(this).closest('.toggle_container').prev('.trigger').find('.status');
    console.log($status.length);
            if (a != b) {   // if a/b!=1, then a!=b
                $status.text("OPEN").css("color", "green");
            } else {
                $status.text("CLOSED").css("color", "red");
            }
            $(this).text(a + " / " + b);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

String=880814 now i want to display this string as 88/08/14 by either means either
I want to display tabular type data, but it will not be coming from
I want to display a thumbnail image in a cell of tableViewController , this
I want to either display a message in the console or a pop up,
I want to write a basic if statement on my site to display either
I want a list of items that can display either an item's 'greek' or
I want to display either a, b, or c. What's happening now is c
I read this and wrote this code: .wholePageDivForCentering { width: 80%; white-space: nowrap; display:inline-block;
I have a simple quiz application and I want display a nice timer /
I want to display the TIME field from my mysql table on my website,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.