10 examples of 'how to get href value of anchor tag in jquery' in JavaScript

Every line of 'how to get href value of anchor tag in jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
20export function getLinkUrl(value: Resource | ResourceLinks, ...rels: ReadonlyArray<string>) {
21 if (!value) {
22 return false;
23 }
24
25 const links = value._links || value;
26
27 for (const rel of rels) {
28 const link = links[rel];
29
30 if (link && link.method && link.href) {
31 return link.href;
32 }
33 }
34
35 return undefined;
36}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

1function get_anchor(document, hash) {
2 hash = hash.replace('#', '')
3 if (!hash) {
4 return;
5 }
6 var anchor = document.getElementById(hash);
7 if (!anchor) {
8 var selector = 'a[name="' + hash + '"]';
9 anchor = $(document).find(selector);
10 if (!anchor.length) {
11 return;
12 }
13 return anchor[0];
14 }
15 return anchor;
16}
4get href() {
5 return this.node.source.value;
6}
59protected getHrefAttribute(): string {
60 const {
61 href,
62 to,
63 urlParams,
64 utmCampaign,
65 utmContent,
66 utmMedium,
67 utmSource,
68 utmTerm
69 } = this.props;
70 if ("string" === typeof href) {
71 return href;
72 }
73 if ("undefined" === typeof to) {
74 return "#";
75 }
76 let urlParamsObject = {};
77 if ("undefined" !== typeof urlParams) {
78 urlParamsObject = urlParams;
79 }
80 /**
81 * @see https://rockcontent.com/blog/parametros-utm-do-google-analytics/
82 */
83 if (utmCampaign || utmContent || utmMedium || utmSource || utmTerm) {
84 urlParamsObject = Object.assign(urlParamsObject, {
85 utm_campaign: utmCampaign,
86 utm_content: utmContent,
87 utm_medium: utmMedium,
88 utm_source: utmSource,
89 utm_term: utmTerm
90 });
91 }
92 const stringified = stringify(urlParamsObject);
93 return `${to}?${stringified}`;
94}
101function anchorLink(element, id, index) {
102 const url = getAnchorUrl(element);
103 return {
104 id,
105 url,
106 label: getAnchorLabel(element),
107 role: url ? 'link' : 'button',
108 index,
109 };
110}
21function looksLikeHref(value) {
22 return !!value.match(/^https?:\/\/[^\/]+\//);
23}
52function getHref(element) {
53 try {
54 return element.href || null;
55 } catch (x) {
56 // IE throws a security exception for urls including username/password:
57 // http://user:password@example.com/
58 return null;
59 }
60}
196resolveHref(el) {
197 if (!el) {
198 return null;
199 }
200 const closestHrefEl = el.closest('[href]');
201 return closestHrefEl ? closestHrefEl.getAttribute('href') : null;
202}
48private _updateHref() {
49 let path = this._cleanUpHref(this._href);
50
51 this.linkHref = this._router.prepareExternalUrl(path, this._query);
52 this.hrefUpdated.emit(this.linkHref);
53}
27pushHref (href) {
28 window.location.hash = href
29}

Related snippets