I want to reuse breadcrumbs structure for a friendly SEO category header. How can I get separator (/) in the output using .text()
function?
Thanks in advance!
$(function(){
var str = $( ".breadcrumb-element").text();
$( "p.text22" ) .html( str );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="breadcrumb">
<a class="breadcrumb-element" href="#" title="Go to Sale">Sale</a>
<a class="breadcrumb-element" href="#" title="Go to Accessories">Accessories</a>
<a class="breadcrumb-element" href="#" title="Go to Scarves">Scarves</a>
</div>
<br><br><br><br>
<p class="text22"></p>
2
Answers
You can use a function in
.text()
to check the index of the element and if its not the 1st element, insert a/
in front of the text.JSFiddle
Well, this is something for CSS.
Just define :after pseudo element to display the delimiter.
Example:
Using JS for this is little bit bloated. But just my 5 cents.