Amarundo Amarundo - 2 months ago 7
jQuery Question

How to use jQuery to substitute text with a function of itself

I have the following

<div class="change">a</div>
<div class="keep">b</div>
<div class="change">c</div>
<div class="change">d</div>
<div class="keep">e</div>
<div class="change">f</div>


I need one jQuery statment to make all elements with
class="change"
to be uppercase.

Answer

Try this :

$(document).ready(function() {
    
    $(".change").each(function(){
        
        var str = $(this).text().toUpperCase();
        
        $(this).text(str);
        
    })
    
})
<div class="change">a</div>
<div class="keep">b</div>
<div class="change">c</div>
<div class="change">d</div>
<div class="keep">e</div>
<div class="change">f</div>
        
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

Comments