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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:49:30+00:00 2026-06-15T21:49:30+00:00

I am trying to do something in JavaScript before following the link in the

  • 0

I am trying to do something in JavaScript before following the link in the href part of a link:

<a href="open.this.page" onclick="doStuff(this);return false; title="follow me">

Question is what does this in doSuff(this) refer to? I was expecting to have to get the href part of the anchor out of it, but when examining it looks like it IS the href and nothing else.

function doSutff(my_arg) {
   alert (my_arg);
   // do stuff
   // follow the href in the link
}

In the above alert I get exactly the href as "http://my.domain/open.this.page".

Is this expected or am I getting it in one browser, but probably not in another?

If that is the normal behavior then how would one get, for example, the rel or title part of an anchor? DOM only?

  • 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-15T21:49:31+00:00Added an answer on June 15, 2026 at 9:49 pm

    "in the above alert I get exactly the href as "http://my.domain/open.this.page".

    Is this expected or am I getting it in one browser, but probably not in another?"

    This is expected. The reason you get "http://my.domain/open.this.page" in the alert is that that is what the default .toString() value is of an <a> element.

    It’s an unusual case. Other elements don’t show an attribute as the .toString() representation.

    If you want to actually do work with the href, you’d need to do this.toString(), or see below…


    "…how would one get, for example, the REL or TITLE part of an anchor?"

    To get other attributes or properties, you’d just do it the usual ways.

    To get the attribute, you can do:

    onclick="doStuff(this.getAttribute('title')); return false;"
    

    Most of the standard attributes map directly to a property on the node, so you could also do this:

    onclick="doStuff(this.title); return false;"
    

    Or since you’re in an inline handler, you can actually do this:

    onclick="doStuff(title); return false;"
    

    The reason that last one works is that handlers assigned from an attribute have a unique scope chain that includes the element itself. This means that properties on the element actually show up as variables.

    Note that this doesn’t work for any other kind of event handler.


    With regard to this, it refers to the element to which the handler is bound.

    What happens to the attribute is that it basically becomes the body of a function assigned to the onclick property.

    So you end up with something like this:

    elem.onclick = function(event) {
        doStuff(this);return false; // Your onclick attribute value
    }
    

    So you can see that this is actually just the normal value found in an event handler assigned to a property.


    Notice also that there’s an event parameter defined. This means that you could change your attribute like this:

    onclick="doStuff(this, event);return false;"
    

    …and it will pass on that parameter, because now your function looks like this:

    elem.onclick = function(event) {
        doStuff(this, event);return false; // Your onclick attribute value
    }
    

    So you can see that your string is actually referencing the normal event parameter of the function.


    This also works in older IE. In IE, the event parameter won’t be defined, so it’ll pick up the global event object.

          // ---------------v----no parameter
    elem.onclick = function() {
    
                    //   v---now it picks up the global event
        doStuff(this, event);return false; // Your onclick attribute value
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to program something like facebook recent update part,so I program following code
I'm trying to do something with javascript (I'm a beginner and I'm studying it)
I'm trying to build something on javascript that I can have an input that
I was trying to do something like Google's Adsense. I believe they use javascript?
I am a beginning javascript programmer. I am trying to create something similar to
I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to
I'm trying something very simple. Upon page load the data in content div is
Hello I'm trying something .. I was reading Jquery traversing documentations some forums, this
I'm trying something like this, but this example does not work. jsObj = {};
I'm trying something like this: [ServiceContract ( CallbackContract = typeof (CallbackContract_1), CallbackContract = typeof

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.