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 6641911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:52:01+00:00 2026-05-25T23:52:01+00:00

I am trying to display a table (or ul) that will contain a navigation

  • 0

I am trying to display a table (or ul) that will contain a navigation bar on my page, but only displays the tabs that will contain jquery called divs present on the html.

Essentially, it’s a single html document that contains all divs, jquery hides all divs but the first, and the nav bar will allow to navigate through each.
Now I am trying to make it easy to use for my client, so that the menu items will only exist if the div for it also exists. I’ve got most of it done, the only thing is actually knowing if a div exists.

I tried using this:

if(document.getElementById("page1")) {
document.write("<b>Good morning</b>");}
else 
{
document.write("<b>Bad morning </b>");
}

When I place the above code within the div page1, it returns true. Is there no way to do it from the top of the page and not within the div?

Thanks!

Update:

As suggested by many, I have used the following:

$j(document).ready(function(){
    //Hide the sections we don't need right away
    $j("#page2").hide();
    $j("#page3").hide();
    $j("#page4").hide();
    if ($j('#page1').length > 0) {
var page = 'Excellent Morning'   ;
}
});

Then when I try to use:

document.write(page);

It displays the following instead:
[object HTMLBodyElement]

  • 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-25T23:52:01+00:00Added an answer on May 25, 2026 at 11:52 pm

    Why not use jQuery since you are already?

    if ($('#page1').length > 0) {
        // do stuff...
    }
    

    EDIT: As davin pointed out, your code should be evaluated after the DOM has been rendered. You can do this by placing it in a $(document).ready call:

    $(document.ready(function() {
        if ($('#page1').length > 0) {
            // do stuff...
        }
    });
    

    EDIT 2: Based on the OP’s edits, a better solution would be to add a placeholder element and to set its content (like FishBasketGordo suggested). An example of this:

    $(document.ready(function() {
        //Hide the sections we don't need right away
        $("#page2, #page3, #page4").hide();
        if ($('#page1').length) {
            $('#myPlaceHolder').html('<b>Good Morning</b>');
        }
        else
        {
            $('#myPlaceHolder').html('<b>Bad Morning</b>');
        }
    });
    

    Somewhere else in the document…

    <span id="myPlaceHolder"></span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a layout with display: table and alike, but it seems
Hello i have a JSP page that displays records from animal table in my
I'm trying to create a SharePoint web part that will display all the users
I'm trying to create an MVC view that will display some data in a
I have created a tool using jQuery that will show certain table rows depending
I'm trying to write a query that will display the minimum value (lowest score)
I'm trying to display a table full of twitter statuses (yes, this is the
Made solution change: I am trying to display a html table of data.. In
I'm trying to inherit QSqlTableModel to make data im my table display in way
I'm trying to understand this bit of code: in display.php: <html> ... <body> <table>

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.