0
Scroll box
I want scroll box for product description when text length more than 100 word.(condition for applying overflow property)
1 ответ
0
In the below code the function checks the word count and if the word count is more or equal to 100 it applies the property of scroll to the p element.
let p = document.querySelectorAll('p');
function getWordCounts(nodeList) {
var wordCount = 0;
for ( var i = 0; i < nodeList.length; i++ ) {
wordCount += nodeList[i].textContent.trim().split(' ').length;
if (wordCount >= 100){
p[i].style.overflow = "scroll";
}
}
}
getWordCounts(p);