What does ownerdocument mean? How is it used?
Dynamically creates a DOM element wrapped by a jQuery object based on the supplied raw HTML markup string. Set a series of properties, events, etc. at the same time.
You can pass a handwritten HTML string, a string created by some template engine or plugin, or a string loaded via AJAX. But there are restrictions when you create input elements, you can refer to the second example. Of course this string can contain slashes (such as an image address), as well as backslashes. When you create individual elements, use closing tags or XHTML formatting. For example, to create a span, you can use $("") or $("") , but $("") is not recommended. In jQuery, this syntax is equivalent to $(document.createElement("span")).
In jQuery 1.8, through $(html,props), you can use any jQuery object method or plug-in. Previously, you could only use a short list of method names, and there was no documented way to add to the list. Now it doesn't need to be a list at all! However, please note that this may cause the behavior of your code to change if the plugin is added with the same name as the HTML attribute.
jQuery(html [, ownerDocument]), jQuery(html, props)
If the incoming string parameter looks like a piece of HTML code (for example, the string contains
$('<p id="test">My <em>new</em> text</p>').appendTo('body');
If the HTML code is a single tag, for example, $('') or $ (''), jQuery will use the browser's native method document.createElement() to create a DOM element. If it is an HTML fragment that is more complex than a separate tag, such as $('
Mynewtext
') in the example above, use the browser The innerHTML mechanism creates DOM elements. This process is implemented by the method jQuery.buildFragment() and the method jQuery.clean(). The relevant content is introduced and analyzed in Sections 2.4 and 2.5 respectively.The second parameter ownerDocument is used to specify the document object to create a new DOM element. If not passed in, it defaults to the current document object.
If the HTML code is a separate tag, the second parameter can also be props, which is a common object containing properties and events; after calling document.createElement() to create a DOM element, the parameter props will be passed to the jQuery method .attr(), and then .attr() is responsible for setting the attributes and events in the parameter props to the newly created DOM element.
The attribute of the parameter props can be any event type (such as "click"). At this time, the attribute value should be the event listening function, which will be bound to the newly created DOM element; the parameter props can contain The following special attributes: val, css, html, text, data, width, height, offset, corresponding jQuery methods: .val(), .css(), .html(), .text(), .data(), .width(), .height(), .offset() will be executed, and the attribute value will be passed in as a parameter; other types of attributes will be set to the newly created DOM element, and some special attributes will also be Cross-browser compatibility (such as type, value, tabindex, etc.); you can set the class style through the attribute name class, but you must wrap the class in quotes because class is a JavaScript reserved word. For example, in the following example, create a p element, set the class style to "test", set the text content to "Click me!", bind a click event, and then insert it at the end of the body node. When the p element is clicked class style will also be switched when testing:
$("<p/>", { "class": "test", text: "Click me!", click: function(){ $(this).toggleClass("test"); } }).appendTo("body");
Sample code:
Dynamicly create a p element (and all the content within it), and append it to the body element. Inside this function, markup to DOM element conversion is achieved by temporarily creating an element and setting the element's innerHTML property to the given markup string. Therefore, this function has both flexibility and limitations.
jQuery Code:
$("<p><p>Hello</p></p>").appendTo("body");
Description:
Creating an element must also set the type attribute. Because Microsoft stipulates that the type of the element can only be written once.
jQuery Code:
// 在 IE 中无效: $("<input>").attr("type", "checkbox"); // 在 IE 中有效: $("<input type='checkbox'>");
Description:
Dynamically create a p element (and all content within it) and append it to the body element. Inside this function, markup to DOM element conversion is achieved by temporarily creating an element and setting the element's innerHTML property to the given markup string. Therefore, this function has both flexibility and limitations.
jQuery Code:
$("<p>", { "class": "test", text: "Click me!", click: function(){ $(this).toggleClass("test"); } }).appendTo("body");
Description:
创建一个 元素,同时设定 type 属性、属性值,以及一些事件。
jQuery 代码:
$("<input>", { type: "text", val: "Test", focusin: function() { $(this).addClass("active"); }, focusout: function() { $(this).removeClass("active"); } }).appendTo("form");
jQuery( html, [ownerDocument] ) 的用途是通过 html 字符串创造相应的 node 节点,jQuery 分为了两种情况,一种是 html 是由一个标签组成的 html 字符串,比如
<span>I'm a SPAN</span>
这时, jQuery 会使用正则表达式匹配出这个 tag 的 tag name ,然后使用
document.createElement( tagName )
来生成这个 node ,而对于多个标签(还包括单个标签的前后有空白字符串)的情况,会这么处理:
先用 document.createDocumentFragment 创建一个 documentFragment
然后 用 document.createElement('p') ,创建一个 p
然后再 p.innerHTML = html ,创建 html 字符串对应的 node 节点
然后从 p 中得到这些节点,并返回
The above is the detailed content of What does ownerdocument mean? How is it used?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



ccsvchst.exe is a common process file that is part of the Symantec Endpoint Protection (SEP) software, and SEP is an endpoint protection solution developed by the well-known network security company Symantec. As part of the software, ccsvchst.exe is responsible for managing and monitoring SEP-related processes. First, let’s take a look at SymantecEndpointProtection(

The Chinese name of the Shift key is the shift key. Analysis: The Chinese name of the 1Shift key is the shift key. It can be used with many keys, so it has many functions. Use the 2shift key to switch input methods, and hold down the Shift key to select multiple files continuously. 3. You can cancel the automatic startup of the software at boot. If you keep holding down the Shift key when turning on the computer, all the startup items that have been set will be cancelled. 4. Select the file you want to delete, then press and hold the Shift key, and then press the Delete key. Then you can delete the file directly. The file will not enter the Recycle Bin. Supplement: What does shortcut key mean? 1 Shortcut key refers to completing an operation through certain specific keys, key sequence or key combination. Many shortcut keys are often related to Ct

How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

The word demo is no longer unfamiliar to friends who like to sing, but many users who have never been exposed to it are curious about what demo means. Now let’s take a look at the meaning of the demo brought by the editor. What does demo mean? Answer: Demo tape. 1. The pronunciation of demo is ['deməʊ] in English and ['demoʊ] in America. 2. Demo is the abbreviation of "demonstration", which generally refers to the preliminary effect of listening to a song before it is officially recorded. 3. Demo is used as a noun to refer to sample tapes and sample records. The meaning of verb is trial (especially software), demonstration and demonstration;

We often see the introduction of how many K screens we have when buying TVs, computers or mobile phones, such as 2.8K screens. At this time, there will be friends who don’t know much about electronic devices and will be curious about what this 2.8K screen means and what the resolution is. What does 2.8k screen mean? Answer: 2.8k screen means that the screen resolution is 2880*18002K, which means the number of horizontal pixels is greater than 2000. For the same size screen, the higher the resolution, the better the picture quality. Introduction to resolution 1. Since the points, lines and surfaces on the screen are all composed of pixels, the more pixels the monitor can display, the finer the picture, and the more information can be displayed in the same screen area. 2. The higher the resolution, the greater the number of pixels, and the sharper the sensed image.

What do game bugs mean? During the process of playing games, we often encounter some unexpected errors or problems, such as characters getting stuck, tasks being unable to continue, screen flickering, etc. These abnormal phenomena are called game bugs, that is, faults or errors in the game. In this article, we'll explore what game bugs mean and the impact they have on players and developers. Game bugs refer to errors that occur during the development or operation of the game, causing the game to fail to run normally or to behave unexpectedly. These errors may be due to

If we want to install a Windows system, we will definitely come into contact with the pe system, but many friends do not understand what the computer system pe means. In fact, it is a pre-installation environment system provided by Windows for users. What does computer system pe mean: Answer: Computer system pe is the windows pre-installation environment, which is the abbreviation of English PreinstallEnvironment. It is mainly used for Windows system installation and maintenance. 1. PE is a subsystem based on win32. It can be started directly from a USB disk or CD when we have not installed it. 2. For ordinary users, the most commonly used tasks in PE are to install Windows systems, repair systems, and maintain disk environments. 3. This

What does 0x0000011b mean when connecting to a printer? Users often encounter various error codes when using computers, laptops or other devices. Among them, 0x0000011b is a common printer connection error code. So, what does connecting printer 0x0000011b mean? First, we need to understand the basic principles of printer connection. When we need to print files from the computer, we usually need to connect the printer to the computer for data transfer between the two. This connection can be made via
