HTMLTemplateElement: htmlFor property
HTML DOM
HTML DOM
The htmlFor property of the 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 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-identifier
Specifications
Browser compatibility
See also
- HTMLTemplateElement