Removing prefixes (select, from, comma)
The following bit of code removes the word “Select” from variant selection drop-down menus, the word “From” from the price of the products which have variable prices depending on variants, and also removes all commas (“,”) from price indications, for aesthetic reasons.I placed this code into the footer section.
HTML:
JAVASCRIPT: //remove all select from variants function removeSelectPrefix() { // Get all select elements on the page const selects = document.querySelectorAll('select'); // Iterate through each select element selects.forEach(select => { // Get the first option element const firstOption = select.options[0]; // Check if the first option exists and its text starts with "select" if (firstOption && firstOption.text.toLowerCase().startsWith('select')) { // Remove the prefix "select" from the text firstOption.text = firstOption.text.replace(/^select\s*/i, ''); } }); } removeSelectPrefix(); //remove all from and commas from prices var elements = document.querySelectorAll('.product-price'); elements.forEach(function(element) { var text = element.textContent; text = text.replace('from', ''); text = text.replace(',', ''); element.textContent = text; });
CSS:
COMMENTS:
Leave a comment: