Umeed Umeed - 4 days ago 5
HTML Question

How to insert title of a html page into the text of an anchor tag?

I am using a CMS and creating a breadcrumb in a page wrapper that will be applied to multiple pages, and what I wanted to do was take the

<title>
of the page being viewed and insert it into the breadcrumb, the breadcrumb will dynamically change for each page. Unfortunately the CMS' internal built-in functions doesn't allow me to simply insert the [[S80:frID]] which pulls the page id # dynamically, I have to manually input the page ID # which then removes the dynamic aspect. So I wanted to resort to Javascript

I'm certain I can retrieve the title by doing:

<script>
$(document).ready(function() {
var pgTitle = document.title;

$("#pullTitle").text(" " + pgTitle);

});
</script>


but how would I take that and insert it into the text of an anchor tag:

<a id="#pullTitle" href="internalpage"> </a>


What I've tried above doesn't do anything. If anyone has any suggestions, I'd greatly appreciate it.

Thanks!

Answer

I think the issue is simply the # in the anchor ID. The # in the jquery selector tells it to look at element IDs (as opposed to a . for classes)

If you remove that this should work!

Comments