How can I get link text using jQuery?
My link is:
<a href="htp://www.google.com" id="id1">google site</a>
I need to get "google site" using jQuery.
To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.
Answer: Use the jQuery . attr() Method attr() method to dynamically set or change the value of href attribute of a link or anchor tag. This method can also be used to get the value of any attribute.
Change an existing hyperlinkRight-click anywhere on the link and, on the shortcut menu, click Edit Hyperlink. In the Edit Hyperlink dialog, select the text in the Text to display box.
The :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element. This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).
That is the text shown to the user in UI not the name. To get that you use a jQuery's text method.
Use the .text()
method as
$('a').text();
Even you can use a variable to get the value to, for example:
var hyperLinkText = $('a').text(); // get the name
$('element').html(hyperLinkText); // write it somewhere
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With