I am facing an issue with a simple JavaScript code that aims to target an element within an angular view:
var buttons = document.querySelectorAll('.msg-type i');
console.log(buttons.length);
When I run this code, it incorrectly prints out 0 on the console, even though there are actually 3 elements present on the page.
The root of the problem lies in the fact that my script is embedded in the index page rather than directly in the view itself. I want to avoid breaking up my script into smaller parts to prevent multiple HTTP requests and ultimately reduce load time.
Is there a way for me to execute this script as soon as my view loads?