I am creating breadcrumbs using XML with the following code:
// <![CDATA[
var root = null;
$(document).ready( function(){
//insert div into hero module to accept breadcrumb
$.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"); //.attr("href",element_url);
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:
Copy code
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!