Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
I want to change href of anhor tag on all subpages except homepage or main page of website using Javascript or any other method

Hello guys this must be very simple but I am not able to figure it out.

I want href in some nav links that are in dropdown to change when the user navigates to any subpages of website and remain same when the user is on the homepage for example

when a user is on homepage (www.example.com) href should be

href="#div_id1"

and when the user goes to subpage e.g.=www.example.com/contactpage then

href="www.example.com#div_id1"

I am using dynamic header so can't use different navbar code on other page

below is my code

<li id="dropdownheading" class="nav-item   my-auto dropdown">
  <a class="nav-link dropdown-toggle " href="#" id="navbarDropdown" 
                     role="button" ata-bs-toggle="dropdown" aria-expanded="false">
    Dropdown heading
  </a>

  <ul class="dropdown-menu " aria-labelledby="navbarDropdown">
    <li><a class="dropdown-item" href="#div-id1">div 1</a></li>    
    <li><a class="dropdown-item" href="#div-id2">div 2</a></li>    
    <li><a class="dropdown-item" href="#div-id2">div 3</a></li>
  </ul>
</li>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!