By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

HyperLink text property undefined

P: n/a
HI,
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
function.

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

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

function ShowText(obj)
{
alert(obj.text);
}

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?

Thanks,
Avanti

Jan 2 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
avanti wrote:
function ShowText(obj)
{
alert(obj.text);
}

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?
There is no default property called "text" for anchor elements. You
should use innerHTML as follows:

function ShowText(obj) {
alert(obj.innerHTML);
}
Jan 2 '07 #2

P: n/a
Jim
Avanti,
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
</a>

Hope that helps,

Jim

Jan 2 '07 #3

P: n/a
Thanks guys for the quick reply. It worked!

Jim wrote:
Avanti,
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
</a>

Hope that helps,

Jim
Jan 2 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.