Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Im looking a way to change the following HTML:

<div class="votes">Rating: <strong>+5</strong> (from 5 votes)</div>

and produce:

<div class="votes"><div class="calculated-rating">+5</div></div>

Thanks in advance.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery('.votes').each(function(){
        votes = jQuery('strong',this).html();
        jQuery(this).html('<div class="calculated-rating">'+votes+'</div>');
    });                         
});
</script>
share|improve this answer
    
jsfiddle.net/68CjG –  Geert May 8 '11 at 7:19
    
Nice. It owrks like a charm. Thanks. –  José Pablo Orozco Marín May 17 '11 at 8:59
add comment

Its little short.

<script type="text/javascript">
jQuery(document).ready(function(){
var tmp = jQuery(".votes strong").html();
jQuery(".votes").html('<div class="calculated-rating">'+tmp+'</div>')
});
</script>
share|improve this answer
    
this will only work if there is one instance of .votes, otherwise every .votes div will show the value of the first instance. –  Milo May 21 '11 at 17:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.