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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:37:09+00:00 2026-06-13T16:37:09+00:00

First off, thanks for taking the time to read this question. What a great

  • 0

First off, thanks for taking the time to read this question. What a great community Stack Overflow has 🙂

I need to change the title tag of a page based on the text contained in the h1 element on that page.

I’ve been searching around, and I have found the “document.title” Javascript function. I’ve been playing around with it, trying to pull the text from my h1 element that has the class of “Category-H1”.

<script type="text/javascript">
    document.title = document.getElementsByClassName("Category-H1");
</script>

However, it is just setting the page title to “[object HTMLCollection]”, which as I understand is a null value. Is JS the best was to do this? I know my code is jacked, any tips?

Thanks in advance! – Alex

Edit

I have been informed that line of code returns a collection object and not a string. It was pointed to a code example of:

setTimeout(function () { document.title = "iFinity User Profile - " + document.getElementById("test").outerText; }, 1000); 

However, this code produces a page title of “iFinity User Profile – undefined”. I have the h1 element on that page set to the id of “test”.

  • 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-13T16:37:10+00:00Added an answer on June 13, 2026 at 4:37 pm

    You’re almost there.

    [object HTMLCollection] is not a null value–it is the string representation of a collection of html elements. You want to choose the first one and then get the inner html from it.

    document.getElementsByClassName("Category-H1")[0].innerHTML
    

    Also, make sure you do this after the document has loaded. You can either do this by adding the script at the end of your document, or have it run on the onload event of the body.

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

Sidebar

Related Questions

First, thanks for taking the time to read this. I'm having some difficulties with
First off good day and thanks for taking the time to answer my question.
and first off thanks for your time to look at this. For a research
First off thanks for writing this class . It has made life much easier
JAVA: First off, Thanks so much for taking the time to look at my
First off thank you in advance for taking time to help me with this,
First of all thanks for taking your time to help me with this. Sorry
First off, let me thank you if you're taking the time to look at
First off, thanks in advance for your help. This issue is driving me nuts.
First off, a big thanks to the people behind the new boost::geometry library! This

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.