HyperLink text property undefined

Discussion in 'Javascript' started by avanti, Jan 2, 2007.

  1. avanti

    avanti Guest

    I have a HyperLink in my code. It has a OnClick function defined. I am
    trying to access the text property of the HyperLink in my JavaScript

    <CoreCtrl:Controls.WebControls.HyperLink id="securityCodeLink" text="My

    Text" OnClick="ShowText(this);" Href="#" CssClass="textSmall"
    runat="server" />

    function ShowText(obj)

    I also tried getting a var for the hyperlink with its id and showing
    its text. It says 'undefined' instead of 'My Text'. Am I doing
    something wrong?

    avanti, Jan 2, 2007
    1. Advertisements

  2. There is no default property called "text" for anchor elements. You
    should use innerHTML as follows:

    function ShowText(obj) {
    Chad Burggraf, Jan 2, 2007
    1. Advertisements

  3. avanti

    Jim Guest

    You can determine the text attribute value in this manner:
    <a href="#"
    text="sometext should go here"
    onClick="alert(this.getAttribute('text'))"Show the Text Attribute Value

    Hope that helps,

    Jim, Jan 2, 2007
  4. avanti

    avanti Guest

    Thanks guys for the quick reply. It worked!
    avanti, Jan 2, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.