Relative Content

Tag Archive for javascriptjqueryperformance

How can I make this jQuery function run faster?

I have four <a> tags on a page; they need to be enabled or disabled depending on a user’s assigned role. (I’m resetting the href value and reducing opacity on the disabled elements.) Right now, there’s a 50% chance that not all of the elements will be evaluated on page load (but they successfully evaluate on reload). In development, I had to use a nested setTimeout() to get them to evaluate at all. What can I do to speed up the execution of the code? Perhaps it shouldn’t be running inside of $(document).ready()? Is my approach all wrong? TIA for your help!