javascript - How to remove hyphen in span? (jQuery) -
i have breadcrumbs generate hyphen inside specific link.
<div class="breadcrumbs"> <span class="home"> <a href="#"><span property="name">home</span></a> </span> <span> <a href="#" class="post post-vehicle-archive"><span property="name">books-for-sale</span></a> </span> <span> <a href="#" class="book-name"><span property="name">soup sould</span></a> </span> </div> i want remove hypens inside class="post post-vehicle-archive".
this code tried far:
<script type="text/javascript"> var j = jquery.noconflict(); j(function() { var gettermname = j('.breadcrumbs .post.post-type-archeive > span'); j(gettermname ).text(value.replace(/\-/g, " ")); }); </script> the result should "books sale"
any appreciated.
try make use of receiver function of .text()
var gettermname = j('.breadcrumbs .post.post-type-archeive > span'); gettermname.text(function(i,value) { return value.replace(/\-/g, " ") }); if want change text title case use below code,
var gettermname = j('.breadcrumbs .post.post-type-archeive > span'); gettermname.text(function(i,value) { return value.replace(/\-/g, " ").split(" ").map(function(function(val){ return val.charat(0).touppercase() + val.slice(1); }).join(" "); }); or don't make things complex,
js:
var gettermname = j('.breadcrumbs .post.post-type-archeive > span').addclass("titlecase"); gettermname.text(function (i, value) { return value.replace(/\-/g, " ") }); css:
.titlecase { text-transform: capitalize; }
Comments
Post a Comment