The second parameter of the jQuery of method is explained in detail

  • 2020-06-03 05:46:26
  • OfStack

The second argument to the jQuery() method can be used in the following ways:

1.jQuery(selector, [context])

This is equivalent to $(context).find (selector) or context.find (selector)

2.jQuery(html, [ownerDocument])

The document interprets ownerDocument as: "Create the document where the DOM element resides."

That said, if you're writing a script for document, say, or opening a new window with window.open, you might want to use it

3.jQuery(html, props)

This should be more common, post the code directly:


$("<input>", {

 type: "text",

 val: "Test",

 focusin: function() {

  $(this).addClass("active");

 },

 focusout: function() {

  $(this).removeClass("active");

 }

}).appendTo("form")

That is, the attributes in props will be set to the newly created tag just like the.attr () method 1

This is the end of this article, I hope you enjoy it.


Related articles: