I have a <div id="bread"></div>
and I am trying to display breadcrumbs where one of the string contains Tab3 »
.
Its like Tab1
> Tab2
> Tab3 »
> Tab4
except that >
is an arrow-right.png
image.
I want to remove »
or »
from Tab3 »
.
I want to search if the selected tab has »
or »
in it and if it does then I want to replace it with ""
so that Tab3 »
becomes Tab3
.
I've tried the following but it doesn't seem to work.
$("document").ready(function() {
var crumbs = $("a.selected");
jQuery.each(crumbs, function() {
if(this != crumbs.get([0])) {
$("#bread").append(" ");
}
$("#bread").append("<img src='<c:url value="/resources/images/arrow-right.png" />' />" + " ");
var crumb = $(this).html();
var slicedCrumb;
if(crumb.indexOf(' » ') != -1) {
slicedCrumb = $(this).html().replace(' » ', '');
$("#bread").append(slicedCrumb);
}
else {
$("#bread").append(crumb);
}
});
});
I also tried to use »
at the place of »
but that din't seem to work either.
$("document").ready(function() {
var crumbs = $("a.selected");
jQuery.each(crumbs, function() {
if(this != crumbs.get([0])) {
$("#bread").append(" ");
}
$("#bread").append("<img src='<c:url value="/resources/images/arrow-right.png" />' />" + " ");
var crumb = $(this).html();
var slicedCrumb;
if(crumb.indexOf(' » ') != -1) {
slicedCrumb = $(this).html().replace(' » ', '');
$("#bread").append(slicedCrumb);
}
else {
$("#bread").append(crumb);
}
});
});
I've spent quite sometime reading other posts on the given subject but somehow I am not able to get it working. Could someone help me understand what am I missing here? I am using jquery-1.5.js
to run this code. Do I need to use the newer version of jquery
or any other library as well to get it working?
»
coming from a source that you control (e.g., CMS)? Perhaps you could save yourself a lot of effort by sanitizing the data at the source.