Skip Navigation

[Resolved] Split: How to preserve the JS to remove the last comma

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by ferruccioR 2 years, 1 month ago.

Assisted by: Christopher Amirian.

Author
Posts
#2568991

Hi Cristopher,
I solved the view problem, now you can see it is working fine.
I have only a request.

I have a list of authors separated by coma and I need to hide the last coma of the list.

I added this code and it works fine on the first page:

(function toglicoma()
{
var spans = document.getElementsByClassName('blocco-autore');
var l = spans.length;
for (var i=0;i<l;i++) {
var ele = spans[i].getElementsByClassName('coma');
var lastEle = ele[ ele.length-1 ];
lastEle.parentNode.removeChild(lastEle);

}
return false;
})(jQuery);

But when I click on my load more button the function doesn't work on the second page.

How can I add the function to it?

Thank you so much.

#2568997

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

This will be a complicated thing to do, as this part of the code that you have:

var spans = document.getElementsByClassName('blocco-autore');

Selects something that is not available when new content is loaded via Ajax.

Maybe you can use this jQuery method to run your function whenever an Ajax call is completed:

jQuery(document).ajaxComplete(function(event, xhr, settings) {
  // Call toglicoma() again to remove the last comma from the list of authors
  toglicoma();
});

I'm sure you will understand that this is going to a territory which is outside of our support scope as it is not directly related to Toolset anymore, and it is something related to your custom Javascript code.

Thank you.

#2570267

Hi Christopher,
it doesn't work, but I solved the issue with another solution.

Thank you!