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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:17:56+00:00 2026-06-16T08:17:56+00:00

Need some help with this code I got off the net $(document).ready(function(){ jQuery(.linkbar li).each(function(){

  • 0

Need some help with this code I got off the net

$(document).ready(function(){
jQuery(".linkbar li").each(function(){
var href = jQuery(this).find('a').attr('href');
if (href === window.location.pathname) {
$(this).addClass('current');
}
});
});

if I do
document.write(href);

I get “undefined”

If I place var href = jQuery(this).find('a').attr('href'); before .each() function it changes all my links to the current class

below is my HTML and CSS
I need to change the css link for the current page, I’m not too good with Jquery/JS. Please explain to me what the problem is and how to solve it.

<div class ="linkbar">

<a href = "/HTS/about-us.php"><li> ABOUT US </li> </a>
<a href = "service.php"><li> SERVICES </li> </a>
<a href = "download.php"><li> DOWNLOAD </li> </a>
</div>

CSS

.linkbar li{
text-decoration:none;
float:left;
list-style-type: none;
font-size:11px;
width:auto;
padding:9px 18px 9px 18px;
}

.current{
background-color:#fecd0f;
vertical-align:center;
color:#fff;
}
  • 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-16T08:17:59+00:00Added an answer on June 16, 2026 at 8:17 am

    well, buddy you have .find() which finds inside the element and you anchor tag as parent of li tag so instead of that use this:

    var href = $(this).parent('a').attr('href');
    

    if it was this you have this:

    <li><a href = "/HTS/about-us.php"> ABOUT US  </a></li>
    <li><a href = "service.php"> SERVICES </a></li>
    <li><a href = "download.php"> DOWNLOAD  </a></li>
    

    still never use find() but use this :

    var href = $(this).children('a').attr('href');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help understanding this bit of code pre { white-space: pre; white-space:
I need some help in combining a stored procedure with another function. I've got
So, I need some code help. I've got an awkward little MySQL table that
Got stuck and need some help, This should be relatively simple but it's been
hi guys i need some help here^^ i got a tag <html> <head> function
I need some help. I've got some php code which I want on every
Need some help with this problem in implementing with XSLT, I had already implemented
I need some help revising this. It keeps only displaying 0s as the temp.
I really need some help with this as I have been trying to fix
We Really need some help on this one: We've Struggled with all the Apple

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.