"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Include jQuery in the JavaScript Console for Non-Integrated Websites?

How to Include jQuery in the JavaScript Console for Non-Integrated Websites?

Published on 2024-11-07
Browse:552

How to Include jQuery in the JavaScript Console for Non-Integrated Websites?

Including jQuery in the JavaScript Console

Including jQuery in the JavaScript console can be beneficial for websites that lack its integration. This allows developers to harness jQuery's capabilities, such as retrieving the number of rows in a table, even on websites that don't natively support jQuery.

To include jQuery in the JavaScript console, simply follow these steps:

  1. Open your browser's JavaScript console.
  2. Paste the following code into the console:
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

This script creates a new script element, assigns it the jQuery CDN URL, and appends it to the document's head. By allowing time for the script to load, jQuery becomes available for use.

Note: If the website uses scripts that conflict with jQuery, you may encounter issues.

Update: To enhance convenience, you can create a bookmark with the following code as its URL:

javascript: (function(e, s) {
    e.src = s;
    e.onload = function() {
        jQuery.noConflict();
        console.log('jQuery injected');
    };
    document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')

This bookmarklet will inject jQuery into the current webpage when clicked. Replace the CDN URL with your preferred version if necessary.

Release Statement This article is reprinted at: 1729175836 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3