jqueryjquery-pluginsjquery-1.5jquery-3

Syntax issue when trying to rewrite a Jquery plugin from version 1.5 to version 3.3


I found this JQuery plugin that looks pretty good for my project. But sadly, it was written way back in 2010, and it can't work with JQuery 1.6+.

As the source code isn't very long, I've then decided to rewrite it to make it works with JQuery 3.3.1 which I use. But I got stuck very quickly because there is a redundant syntax that I don't know and don't understand :

$('<div/>',{
                className   :   'description',
                html        :   descHTML
            });
$images = $('.images',$mg);
$('.images div:visible:last',$this);
...

What does this syntax means ? I used to know the selector syntax $(selector) without comma in between, but not $(syntax1, syntax2) with comma "," !!!

Please what does that syntax means and how could I reproduce it with JQuery 3.3.


Solution

  • $(selector, parentSelector|parentObject);
    

    This format of a selector is used to find elements within another element. $(selector) is shorthand for $(selector, document). If you give a second parameter to the selector, it will use that as the context it searches in, rather than the global document.

    Ref. http://api.jquery.com/jQuery/#jQuery1