In a scroll function, i want for a variable to get the id value of a element of a loop, under a certain condition, and after the loop, for that element to get its font-weight as bold. After another scroll event, the element choosen may change and the old one gets its font-weight back to normal.
The loop itself works well, the variable gets the id value, but after the loop, i cant get the last element of the loop to change its font weight when the variable gets its id value.
I can only get it to work if i hard-code it, but thats not a ideal solution.
I have tried other types of css, same problem. For some reason, if i take out the back to normal font-weight line, it does get to change its font-weight to bold. The debugger doesnt say anything.
This is the page code
<div id="barrl2">
<span id="meta0b">properties</span>
<span id="meta1b">properties</span>
<span id="meta2b">properties</span>
<span id="meta3b">properties</span>
<span id="meta4b">properties</span>
<span id="meta5b">properties</span>
</div>
<div id="main3">
<div id="meta0" class="tit1">properties</div>
<div id="meta1" class="tit2">properties</div>
<div id="meta2" class="tit2">properties</div>
<div id="meta3" class="tit2">properties</div>
<div id="meta4" class="tit2">properties</div>
<div id="meta5" class="tit2">properties</div>
</div>
<script>
assinala(6);
</script>
This is the function, with the hard code part inactive
function assinala(n) {
$(document).ready(function(){
assi = "#meta0b";
$(assi).css('font-weight', 'bold');
$(window).scroll(function () {
for (let i = 0; i < n; i++) {
if ($(window).scrollTop() >= $("#meta" + i).offset().top) {
assi = "#meta" + i + "b";
}
$(assi).css('font-weight', 'bold');
if ($("#meta" + i + "b") != assi) {
$("#meta" + i + "b").css('font-weight', 'normal');
}
}
/*
if ($(window).scrollTop() >= $("#meta5").offset().top) {
$("#meta5b").css('font-weight', 'bold');
}
*/
})
});
}






