Please help me tweak my code! (Trying to dynamically add <a> tag)
I am creating breadcrumbs using XML with the following code:
- // <![CDATA[
- var root = null;
- $(document).ready( function(){
-
- $.get( "/_assets/xml/sitemap.xml",
- function( data ) {
- root = data;
- var pathname = window.location.pathname;
-
- var local_url = "*[url=" + pathname + "]";
- var currpage = $(root).find(local_url).attr("name");
- var parentEls = $(root).find(local_url).parents();
- var mapped = $(parentEls).map(function () {
- var element = $(this).attr("name");
- var element_url = $(this).attr("url");
- var element_wrap = $(this).wrap('<a href="' + element_url + '"/>').attr("name");
- return element_wrap;
- })
- .get()
- .reverse()
- .join(" / ");
-
- $("#breadcrumb").append("<p>" + mapped + " / " + currpage + "</p>");
- } );
- } );
- // ]]>
The breadcrumbs are displaying perfectly, I'm just having a hard time inserting the <a> tag via .wrap() here:
- var element_wrap = $(this).wrap('<a href="' + element_url + '"/>').attr("name");
I want to attach a link to each element's URL and return the name of the tag. The <a> tags aren't being applied here, what am I doing wrong?
Thanks for any suggestions!