0

The jQuery home page contains several blocks of code that use $, such as the following.

$( "button.continue" ).html( "Next Step..." )

However, no where on that page or in the jQuery API Documentation page does it say what $ means in this context.

This makes understanding jQuery very difficult and in some case it makes it impossible.

I am asking this question because I need to resolve an issue in a browser extension I am responsible for maintaining but I am not certain how. The issue I need to resolve is related to the following line of code.

$(document).on('DOMNodeInserted', InspectPage.OnNodeInserted);

This line of code causes the following warning.

Listener added for a synchronous 'DOMNodeInserted' DOM Mutation Event. This event type is deprecated (https://w3c.github.io/uievents/#legacy-event-types) and work is underway to remove it from this browser. Usage of this event listener will cause performance issues today, and represents a risk of future incompatibility. Consider using MutationObserver instead.

When researching how to resolve this issue I found the Mutation events will be removed from Chrome page that contains the following code block.

// Replacement mutation observer code:  
const observer = new MutationObserver(mutationList =>  
  mutationList.filter(m => m.type === 'childList').forEach(m => {  
    m.addedNodes.forEach(doSomething);  
  }));  
observer.observe(target,{childList: true, subtree: true});

I know that for my purposes I need to replace doSomething with InspectPage.OnNodeInserted. The problem is that I do not know what to replace target with when adding the above code to my extension because the jQuery documentation does not bother to explain what $ is. Since I do not know what $ is, I also do not know what $(document) is.

Benilda Key
  • 2,836
  • 1
  • 22
  • 34
  • *"...the jQuery documentation does not bother to explain what `$` is"*: Quoted from that [documentation](https://api.jquery.com/jquery/): *"`jQuery()` — which can also be written as `$()` — searches through the DOM for any elements that match the provided selector"* – trincot Aug 31 '23 at 18:10
  • 1
    In the first paragraph of `jQuery`'s API documentation is this line: *"If you're new to jQuery, we recommend that you check out the [`jQuery` Learning Center.](https://learn.jquery.com)"*. That eventually leads here: https://learn.jquery.com/about-jquery/how-jquery-works/, which explains the `$` usage as: *"The `jQuery` library exposes its methods and properties via two properties of the window object called `jQuery` and `$`. `$` is simply an alias for `jQuery` and it's often employed because it's shorter and faster to write."* – Tim Lewis Aug 31 '23 at 18:11
  • @TimLewis The problem is that if you are starting out at the jQuery home page, you have to follow four links to get to that page. Then that quote is very vague because jQuery apparently can mean many different things including the jQuery library, the window.jQuery property, the jQuery() method, or a jQuery type. I still am not certain what $ means because of this. – Benilda Key Aug 31 '23 at 23:57
  • *"I still am not certain what $ means [...]"* - `$` is an alias for `jQuery`. Where you can use `jQuery('...')`, you can instead use `$('...')` since, for some, typing `jQuery()` over and over is too much. That's it. I'm sorry that 4 links is too many, but there also isn't anything we can do here on Stackoverflow except point you to said documentation... – Tim Lewis Sep 01 '23 at 01:49

0 Answers0