Simon
Simon

Reputation: 2125

Append text to text hyperlink using javascript

I am working in sharepoint and using a 'content editor' to embed HTML hyperlinks on the page.

<a href="/New%20Applications.aspx">New Applications</a>

Now I would like to somehow get the total number of items from that list and display the number in brackets in the hyperlink, ie

New Applications(5)

I am familiar with using javascript on a SharePoint page and can get the value, but how would I then use javascript (if I should use JS) to add the value found to the hyperlink text?

Appreciate any assistance!

Upvotes: 1

Views: 506

Answers (2)

El Guapo
El Guapo

Reputation: 101

If you can get the number of applications in a variable, let's call it newApps, then:

<a href="/New%20Applications.aspx">New Applications (<script>document.write(newApps);</script>)</a>

Upvotes: 0

David Francis
David Francis

Reputation: 352

If you give the hyperlink an ID (you would end up with <a id="someID" href="...">New Applications<a> you can use this code:

 document.getElementById('someID').innerHTML += value;

This will append whatever is in value to the end of "New Application"

Upvotes: 1

Related Questions