Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

removing first 14 characters from string, works on fiddle but not site

I have this fiddle I have been testing to remove the first 14 characters from a span on my website, I’m trying to remove "Published on:"

https://jsfiddle.net/tetzuro/3ym8jwcu/

For some reason it won’t work on the page, which is https://www.homecarepulse.com/blog/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’m not sure what I am missing from my code but here it is for reference

$('.fusion-tb-published-date').text(function(_, txt) {
  return txt.slice(14);
});
<div class="fusion-meta-tb fusion-meta-tb-1 floated" style="padding-bottom:15px;min-height:36px;font-size:16px;">
  <span class="fusion-tb-published-date">Published On: Jul 28, 2022</span><span class="fusion-meta-tb-sep"></span>
  <span class="fusion-tb-author">By
<span><a href="" rel="author">author</a></span></span>
  <span class="fusion-meta-tb-sep"></span>
  <span class="fusion-tb-published-read-time">23.8 min read</span>
  <span class="fusion-meta-tb-sep"></span>
</div>

>Solution :

You are getting an error in the console

Uncaught TypeError: $ is not a function.

That means you are, most probably using it before the $ is initialised or not initialising it at all.

The fastest solution for this is to replace $ with jQuery:

jQuery('.fusion-tb-published-date').text(function (_,txt) {
    return txt.slice(14);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading