vektor
vektor

Reputation: 117

Change text options in Wordpress

I generated this form with a wordpress plugin and i can't put spaces on text. I want change text of options like this: UnaEstrella -> Una Estrella ... (not value text)

<select id="topics" class="taxonomies-filter-widget-input" name="topics">
    <option value="0">Todas</option>
    <option class="level-0" value="unaestrella">UnaEstrella</option>
    <option class="level-0" value="dosestrellas">DosEstrellas</option>
    <option class="level-0" value="tresestrellas">TresEstrellas</option>
    <option class="level-0" value="cuatroestrellas">CuatroEstrellas</option>
    <option class="level-0" value="cincoestrellas">CincoEstrellas</option>
</select>

Is possible change too with images?

Upvotes: 0

Views: 70

Answers (1)

The Alpha
The Alpha

Reputation: 146219

I think you want something like this

function camelToSpc(str) {
    return str.replace(/([a-z\d])([A-Z])/g, '$1 $2');
}

$(function(){
    $('select#topics option').each(function(){
        var txt = $(this).text();
        $(this).text(camelToSpc(txt));
    });
});

DEMO.

Update :

Make sure jQuery is added and replace $ with jQuery or try

(function($) {
    $('select#topics option').each(function(){
        var txt = $(this).text();
        $(this).text(camelToSpc(txt));
    });
})(jQuery);

DEMO.

Upvotes: 1

Related Questions