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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:41:36+00:00 2026-06-04T10:41:36+00:00

I have a simple link with a hashtag in it. ie: <a class=page_navigation href=#something>click</a>

  • 0

I have a simple link with a hashtag in it. ie:

<a class="page_navigation" href="#something">click</a>

On clicking this, I would like to just end up with the ‘something’ part (minus the hash) in a var.

So far I have

$('.page_navigation').click(function(e)
{
    e.preventDefault();
    var href = $(this).attr('href');
});

Obviously I just end up with ‘#something’ in my href var with the above code, and I understand I could do some kind of regex (not sure how yet) to strip the #, but I wonder if there is an easier way to access this part of the href I’m unaware of, without having to go through some find and replace code.

Any ideas?

Note: I also know I could store the ‘something’ in a data tag, but I’m trying to keep this code as DRY as possible.

  • 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-04T10:41:37+00:00Added an answer on June 4, 2026 at 10:41 am

    If you know it has a # in it, you can use this:

    $('.page_navigation').click(function(e)
    {
        e.preventDefault();
        var hash = this.href.replace(/^.*#/, "");
    });
    

    If you don’t know whether it has one it it or not, you can use this:

    $('.page_navigation').click(function(e)
    {
        e.preventDefault();
        var hash = "";
        if (this.href.indexOf("#") {
            hash = this.href.replace(/^.*#/, "");
        }
    });
    

    In HTML5, you could use:

    this.hash
    

    but that is only for the latest browsers.

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

Sidebar

Related Questions

I have a simple wordpress/php landing page with a click-to-call link: <a href=tel:888-555-7777 target=_self>888-555-7777</a>
I have a simple click handler that will alert its link's href as in:
I have a simple link in a menu <a id=Home href=Amico-Bio-Home-Page></a> to which i
I have a simple GAE app that includes a login/logout link. This app is
I have the following bit of code, simply: $(function() { $('a.add-photos-link').live('click', function(e) { $(this).colorbox({
I would like to prevent the default behaviour of a click on a link.
I have simple HTML code: <input type='hidden' name='cat_id' value='123'/> <a href='#' class='edit'>Edit</a> <a href='#'
I have a simple link: <a href=# id=test>Test Link</a> I want to get an
I have a simple link click simulation that I want to do using jQuery.
So, using IE as my browser, I have a simple link... <a href=test.jpg>Image Link</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.