I am trying to find the first link of my page which url fit to "AAA"
(example).
I first try to get the links with this href:
$('a[href$="AAA"]')
Then selec the first one:
$('a[href$="AAA"]')[0]
Then target the title attribute of this link
$('a[href$="AAA"]')[0].attr("title");
But all of this return me "undefined", at each step. How to do that?
Example anchor:
<a href="contents/medias/images/news/news_test_big.jpg" title="Nouvelle réalisation en ligne 1 FR" target="_blank" class="imageLink">
A link has two ends -- called anchors -- and a direction. The link starts at the "source" anchor and points to the "destination" anchor, which may be any Web resource (e.g., an image, a video clip, a sound bite, a program, an HTML document, an element within an HTML document, etc.).
The href attribute specifies the URL of the page the link goes to. If the href attribute is not present, the <a> tag will not be a hyperlink. Tip: You can use href="#top" or href="#" to link to the top of the current page!
The HREF is an attribute of the anchor tag, which is also used to identify sections within a document. The HREF contains two components: the URL, which is the actual link, and the clickable text that appears on the page, called the "anchor text."
URL Rating (UR) shows the strength of a page's link profile on a 100-point scale. The bigger the number, the stronger a page's link profile is.
How about:
$("a[href='AAA']").first().attr("title")
// or
$("a[href='AAA']:first").attr("title")
Then it depends if you want the href to be equal to 'AAA', contains it, starts/ends with it. In that case you wouldn't use href=
but href$=
for instance. Neil's answer contains the different types of tests you can use.
If you could post your HTML code it would help as well.
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