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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:42:27+00:00 2026-06-05T22:42:27+00:00

I am trying to change the link of a basic <a> . It has

  • 0

I am trying to change the link of a basic <a>. It has no id. It is located in a header.aspx file that I cannot access directly. It is also the first grandchild element of a div with the id “SiteMenu”. From that div I would like to use the following script. (I can put script refs in the footer and upload to the Theme dir):

document.getElementById("SiteMenu").childNodes[0].childNodes[0].href = "/search.aspx?keyword='+'&page=1";`

also tried:

document.getElementById("SiteMenu").firstChild.childNodes[0].href = "/search.aspx?keyword='+'&page=1";`

The basic structure of the HTML is:

<div id="SiteMap">
    <p>
        <a href="/home.aspx">Home</a>
    </p>
</div>

I’m no JS pro. From some things I read before posting here, it seems like childNodes.childNodes is an invalid way to search through node levels in JS (or the DOM?).

Is there some other way to manipulate the href of my tag?

  • 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-05T22:42:27+00:00Added an answer on June 5, 2026 at 10:42 pm

    .childNodes[0] won’t have any children since the first child is a text node, containing the line break and space before the <p> (at least in your example). You want to get the first element node.

    For example:

    document.getElementById("SiteMenu").children[0].children[0].href = '...';
    

    See .children [MDN] for more information.


    Alternative you can iterate over each child node and test its .nodeType [MDN] to see whether it is an element node or not.

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

Sidebar

Related Questions

I'm trying to change the styling of the list item that holds my link
I am trying to change the background image of a link when it get
I'm trying to write a jQuery function to change out href of a link,
I'm trying change an input mask for textbox when the the check box has
I am trying to change a link label's fore color but the color won't
I'm trying to change the size of an iframe with a jQuery link to
I am trying to set up a basic layout where the header and footer
I am trying to change the colors of a link using css but for
I've been trying to change the text that's within the #vehicle .partnumber section on
I am trying to change a link programmatically. Example: I want to call a

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.