Changing value inside text field based on body class>?
Briefly

The provided JavaScript code attempts to change the placeholder text of a search input field based on the body class. It checks if the body contains the words "competitions" or "freebies" and updates the placeholder text accordingly. While the logic is sound, debugging is suggested if it’s not functioning. Adding console.log statements can help identify if the conditions are met as expected, ensuring the correct placeholder text is set at page load.
document.addEventListener('DOMContentLoaded', function() { const bodyClass = document.body.className; const searchInput = document.getElementById('PqmIc_title'); if (bodyClass.includes('competitions')) { searchInput.placeholder = 'Search competitions by title, keywords...'; } else if (bodyClass.includes('freebies')) { searchInput.placeholder = 'Search freebies by title, keywords...'; } });
Read at SitePoint Forums | Web Development & Design Community
[
|
]