Activate JQUERY Document ready function only on specific pages in global javascript file

peter liles 556 Reputation points
2021-09-29T13:48:06.097+00:00

I have a drag and drop feature that is activated when particular page is open using the document method. As i understand it is fired every time on page load. I have now placed the code in a javascript file. The trouble is it will now load on all pages that access javascript file when i just want it to load when particular pages load, two?

var srcElement = '';

$(document).ready(function () {

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,252 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 Reputation points
    2021-09-30T02:20:13.9+00:00

    Hi @peter liles ,
    Why you don't put the javascript file in the specific pages instead of in the global? I suggest you could write the drag function in the javascript file and then you could reference the javascript file in the specific pages.

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. peter liles 556 Reputation points
    2021-10-12T19:38:19.87+00:00

    Although i have another page that utilizes same function so i placed into a global file instead of keeping on page.