Baba
Baba

Reputation: 2229

Reading the value of a html a link

I have a link below and will like to read the value "Electric" and store it in a variable

        <a  title="This is cool" id="lnkTranslate">Electric</a>

I tried the code below but no luck. Any ideas please?

        var languageToConvertTo = $('#lnkTranslate').val($(this).html());

Upvotes: 0

Views: 16

Answers (2)

Anthony Sherratt
Anthony Sherratt

Reputation: 475

Use the .text() function like so..

var languageToConvertTo = $('#lnkTranslate').text();

Upvotes: 1

John C
John C

Reputation: 3112

.val() is used to get the value of input tags. .text() will give you the text between the opening and closing tags -

var languageToConvertTo = $('#lnkTranslate').text();

Upvotes: 0

Related Questions