HTMLTemplateElement: htmlFor property
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("HTML DOM")}}{{SeeCompatTable}}
The **htmlFor** property of the {{domxref("HTMLTemplateElement")}} interface is the ID of the Processing Instruction marker to replace with the contents of the associated <template> element. It reflects the value of, and is used to set and get the [for](/en-US/docs/Web/HTML/Reference/Elements/template#for) content attribute.
Value
A string containing the ID of the Processing Instruction marker to replace with the contents of this <template> element.
Description
The for attribute of a <template> element is used for template out-of-order patching using <?marker> and <?start>/<?end> processing instruction markers. Those markers are replaced with the contents of the <template> element when it is parsed and processed.
The htmlFor attribute provides JavaScript access to the attribute value. htmlFor is used instead of for to avoid clashing with the JavaScript for reserved word (this is no longer strictly necessary, so may change in the future).
Examples
Basic usage
<template for="my-identifier"> Lorem Ipsum... </template>console.log(document.querySelector("template").htmlFor);
// my-identifierSpecifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{domxref("HTMLTemplateElement")}}