ProcessingInstruction: thuộc tính target

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thuộc tính target chỉ đọc của giao diện ProcessingInstruction biểu diễn ứng dụng mà ProcessingInstruction nhắm đến.

Ví dụ:

html
<?xml version="1.0"?>

là một chỉ thị xử lý có targetxml.

Giá trị

Một chuỗi chứa tên của ứng dụng.

Ví dụ

Trong tài liệu XML

js
let parser = new DOMParser();
const doc = parser.parseFromString(
  '<?xml version="1.0"?><test/>',
  "application/xml",
);
const pi = doc.createProcessingInstruction(
  "xml-stylesheet",
  'href="mycss.css" type="text/css"',
);
doc.insertBefore(pi, doc.firstChild);

const output = document.querySelector("output");
output.textContent = `Đích của chỉ thị xử lý này là: ${doc.firstChild.target}`;

Trong tài liệu HTML

Dòng chỉ thị xử lý sẽ được xem như và biểu diễn dưới dạng đối tượng Comment.

html
<?xml version="1.0"?>
<pre></pre>
js
const node = document.querySelector("pre").previousSibling.previousSibling;
const result = `Nút chứa chỉ thị xử lý: ${node.nodeName}: ${node.nodeValue}\n`;
document.querySelector("pre").textContent = result;

Đặc tả kỹ thuật

Specification
DOM
# dom-processinginstruction-target

Tương thích trình duyệt

Xem thêm