I'm doing an ajax call an trying to add a class to a DOM element, and then change a value of a property of that class.
I can add the class, but not changing the attribute.
<script>
function load_to_be_analysed_count() {
$.ajax({
url: 'experiments/to_be_analysed/count',
dataType: 'text',
type: 'get',
success: function(data) {
// data is the number of experiments to be analysed, returned from server
if (data >= 0) {
$('#new_experiments').addClass('badger');
console.log($('.badger').css('content')); // DEBUG
$('.badger').css('content', data);
}
},
error: function () {
$('#login-language').html('<p>An error ocurred</p>'); // TODO: just for debug. Maybe console.log
}
});
if ($('#new_experiment').hasClass('badger')) {
$('.badger')
}
}
$(function () {
load_to_be_analysed_count()
})
</script>
HTML before:
<i id="new_experiments" class="fa fa-bell fa-2x icon-grey"></i>
When I load the page, Inspector display none
when console.log($('.badger').css('content')); // DEBUG
is reached.
In Inspector, I can see the above HTML changed to
HTML after:
<i id="new_experiments" class="fa fa-bell fa-2x icon-grey badger" style=""></i>
CSS:
i#new_experiments {
width: 50px;
text-align: center;
vertical-align: middle;
position: relative;
}
.badger:after{
content: "50";
position: absolute;
background: red;
height: 2rem;
top: -0.2rem;
right: 0.2rem;
width: 2rem;
text-align: center;
line-height: 2rem;
font-size: 1rem;
border-radius: 50%;
color: white;
}