Category: Javascript
Alter .img src
Use querySelector to target the img directly: Why document.getElementById(‘MyCssId’).src doesn’t work As for .text, when you apply an ID to an Elementor widget, it is often applied a level up from the actual displayed image If you use this on the ID: You won’t update it.
Alter .textContent
Use querySelector to target the <p> directly: If your innerHTML includes double quotes or newlines You can use backticks instead of quotes: Checking if the ID exists If the text you are inserting has special characters, line breaks, etc Because you are inserting into javascript, json_encode is the best solution. (Note there are no surrounding […]
Alter styling from JavaScript
Elementor Button Widget
Hide objects and sections on page load
Default to all hidden To then display a section Display it if it exists
Show / hide section by ID
You can use .style.display as normal, just make sure when you show it you are using ‘flex’ and not ‘inline’ if the element is a flex! Hide it: Show it
