Currently, I am experimenting with modifying CSS
values using jQuery
. My goal is to include the width
to a .block
element, based on the value of its child element.
Oddly enough, the function does not seem to work when the page initially loads. However, if I execute it through the console
(using Chrome DevTools), it works perfectly fine.
Below is the snippet of my code:
$(document).ready(function() {
$('.gauge').each(function() {
var text = $(this).text();
$(this).parent().css('width', text);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>
<span class="wrap"><span class="gauge ">70%</span></span>
<span class="wrap"><span class=" gauge ">20%</span></span>
<span class="wrap"><span class=" gauge ">10%</span></span>
</li>
</ul>