-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
26 lines (22 loc) · 718 Bytes
/
script2.js
File metadata and controls
26 lines (22 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
document.querySelectorAll('.card').forEach(card => {
const desc = card.querySelector('.project-desc');
const btn = card.querySelector('.see-more-btn');
if (!desc || !btn) return; // skip if either is missing
const fullText = desc.innerHTML;
const words = fullText.split(' ');
if (words.length > 30) {
const shortText = words.slice(0, 30).join(' ') + '...';
desc.innerHTML = shortText;
btn.addEventListener('click', () => {
if (btn.innerText === 'See more') {
desc.innerHTML = fullText;
btn.innerText = 'See less';
} else {
desc.innerHTML = shortText;
btn.innerText = 'See more';
}
});
} else {
btn.style.display = 'none';
}
});