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

  • SEARCH
  • Home
  • 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 8826131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:03:32+00:00 2026-06-14T07:03:32+00:00

I am creating an extremely basic javascript version of tic tac toe. I have

  • 0

I am creating an extremely basic javascript version of tic tac toe. I have already set up the board utilizing a table and assigning borders appropriately.

When the player makes a move an X is placed within the box, and when the computer goes an O.

However my issue is trying to decide if the cell has been “used” meaning that there already exists an X or O within.

Is there a function in javascript which can check for contents within an HTML element or can anyone think of another way to do this? I considered using an array of 9, holding x or o and checking this way, but I ran into the issue of figuring out how to pass the cell number to that function to update the array.

I’m new to javascript so if either of these possibilities exist please let me know or if you have any suggestions of your own!

  • 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-06-14T07:03:34+00:00Added an answer on June 14, 2026 at 7:03 am

    Use textContent and innerText to get the text of an element.

    Example:

    <!doctype html>
    <html>
        <head>
            <title>test</title>
        </head>
        <body>
            <p id="hello-container">Hello, World!</p>
            <script type="text/javascript">
                var el = document.getElementById('hello-container');
                var text = el.textContent || el.innerText || '';
                alert('The text is: ' + text);
            </script>
        </body>
    </html>
    

    Explanation:

    Since IE8- uses innerText and Firefox uses textContent (with other browsers choosing either one side or both), you need to check both properties. We make use of JavaScript’s logical or operator || to check both properties in one line. text = el.textContent || el.innerText will store el.textContent in text if there is a textContent property. If there is not a textContent property (or if textContent is the empty string or just whitespace), then it will try to store innerText in the text variable. Finally, we use || '' to set it to the empty string if neither textContent nor innerText could be found *.

    * This is only necessary if textContent was the empty string/whitespace and innerText did not exist, in which case both would be falsey. Rather than let text be undefined, we store the empty string '' instead.


    If you would like to check to see if HTML is in an element rather than text (this would be helpful if you are using image elements for your X and O) you can use innerHTML. This is standard for all browsers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been tasked with creating an extremely heavy JavaScript site that of course must
I'm creating an XNA game and am getting an unexpected result, extremely low FPS
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
I have created an extremely simple junit test, which creates a null product in
I'm working on a large and extremely messy javascript file, and I would like
I'm working on a extremely basic Java video player project which is my coursework.
I'm creating a game engine using wxWidgets and OpenGL. I'm trying to set up
I've noticed that the Javascript sort function is extremely slow in Internet Explorer versions
So I'm creating my first chrome extension and was extremely confused for a while

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.