Currently, I am facing an issue with applying the top
CSS property to the thead
element of a table while scrolling. I have attempted various methods but have been unsuccessful in achieving the desired outcome.
Initially, I used the scroll
event, however, it did not yield the expected result. Interestingly, modifying the CSS directly in the DOM produced the desired effect, as depicted in the image below.
https://i.sstatic.net/Lpum6.png
Unfortunately, replicating the same behavior using JavaScript has proven challenging. Below is the function I wrote:
$("#container").scroll(function(){
$(".header").css({
"position":"absolute",
"top":"40px"
});
});
I am puzzled as to why this approach is not working with JavaScript. Could you please review my code snippet and offer some insight? You can access my project via this link: Plnkr