Home » Jquery » jquery – Use javaScript functions that apply to specifics page elements

jquery – Use javaScript functions that apply to specifics page elements

Posted by: admin February 22, 2020 Leave a comment

Questions:

Lets say i have 3 pages in my webapp.

  • PageA, this page have a successMessage DIV that show a message.
  • PageB
  • PageC

Right now, i have a jQuery inline script on PageA that apply to the successMessage DIV and that require jQuery but the jQuery lib is loaded after the page is loaded. I do not want to load jQuery lib in the head of the page. I would like to avoid using that inline script and instead i would like to use the jQuery module pattern.. while that doesn’t fix my problem it would help organize my code.

What is the best approach for this webapp to access my scripts in a way that i can attach events or use functions (that require jQuery to be loaded) on elements of specific pages that won’t apply to all pages?

For example, i could have also a successMessage DIV somewhere else… but i do not want the piece of script to apply here.

How to&Answer: