API Reference
This page contains auto-generated documentation for all public symbols with docstrings in HTMLForge.
All Documented Symbols
HTMLForge.VALID_SWAP_STYLES — Constant
VALID_SWAP_STYLESThe set of valid swap styles for hx-swap.
Base.getindex — Method
getindex(elem::HTMLElement, key::Union{AbstractString, Symbol})Get the attribute with the given key from an element.
Base.getindex — Method
getindex(elem::HTMLElement, i::Int)Get the ith child of an element.
Base.length — Method
length(elem::HTMLElement)Get the length of elem's children.
Base.length — Method
length:text::HTMLText)Get the length of text content.
Base.push! — Method
push!(elem::HTMLElement, val::HTMLElement)Push a child onto an element.
Base.setindex! — Method
setindex!(elem::HTMLElement, val::AbstractString, key::Union{AbstractString, Symbol})Set the attribute with the given key on an element.
Base.setindex! — Method
setindex!(elem::HTMLElement, val::HTMLElement, i::Integer)Set the ith child of an element.
HTMLForge.addclass! — Method
addclass!(elem::HTMLElement, cls::AbstractString)Adds the class cls to elem.
HTMLForge.applyif! — Method
applyif!(condition::Function, f!::Function, doc::HTMLDocument)Apply f! to all elements (nested included) in doc for which condition is true.
HTMLForge.applyif! — Method
applyif!(condition::Function, f!::Function, elem::HTMLElement)Apply f! to all elements (nested included) in elem for which condition is true.
HTMLForge.attributevalidation — Method
attributevalidation(attr::AbstractString)Validate if attr is a valid HTML attribute name according to HTML specifications.
Attribute names must consist of one or more characters other than space characters, NULL, quotes, apostrophes, greater-than signs, forward slashes, equals signs, control characters, and any characters not defined by Unicode.
HTMLForge.attrs — Method
attrs(elem::HTMLElement) :: Dict{String, String}Get the attributes of an element.
HTMLForge.breadthfirst — Method
breadthfirst(node)Return a breadth-first iterator over the tree rooted at node.
HTMLForge.classvaluevalidation — Method
classvaluevalidation(class::AbstractString)CSS class values validation.
HTMLForge.findfirst — Method
findfirst(f::Function, doc::HTMLDocument) :: Union{HTMLElement, Nothing}Find the first (PreOrderDFS) element in doc for which f is true.
HTMLForge.findfirst — Method
findfirst(f::Function, elem::HTMLElement) :: Union{HTMLElement, Nothing}Find the first (PreOrderDFS) element in elem for which f is true.
HTMLForge.getattr — Function
getattr(elem::HTMLElement, name::AbstractString, default=nothing) :: Union{String, Nothing}Get the value of an attribute of an element or default if not present.
HTMLForge.getbyid — Method
getbyid(doc::HTMLDocument, id::AbstractString) :: Union{HTMLElement, Nothing}Get the element with the given id from doc.
HTMLForge.getbyid — Method
getbyid(elem::HTMLElement, id::AbstractString) :: Union{HTMLElement, Nothing}Get the element with the given id from elem.
HTMLForge.hasattr — Method
hasattr(elem::HTMLElement, name::AbstractString) :: BoolCheck whether an element has an attribute.
HTMLForge.hasclass — Method
hasclass(elem::HTMLElement, cls::AbstractString)Returns true if elem has the class cls.
HTMLForge.hxattr! — Method
hxattr!(el::HTMLElement, attr::Union{AbstractString,Symbol}, value::AbstractString) -> HTMLElementSet an arbitrary htmx attribute on an HTMLElement in place. The data-hx- prefix is added automatically.
HTMLForge.hxboost! — Function
hxboost!(el::HTMLElement, value::AbstractString="true") -> HTMLElementAdd an hx-boost attribute to progressively enhance links and forms to use AJAX.
HTMLForge.hxconfirm! — Method
hxconfirm!(el::HTMLElement, message::AbstractString) -> HTMLElementAdd an hx-confirm attribute that shows a confirm() dialog before issuing the request.
HTMLForge.hxdelete! — Method
hxdelete!(el::HTMLElement, url::AbstractString) -> HTMLElementAdd an hx-delete attribute to an HTMLElement in place and return the modified element.
HTMLForge.hxdisable! — Method
hxdisable!(el::HTMLElement) -> HTMLElementAdd an hx-disable attribute to prevent htmx from processing this element and its children. Useful for including untrusted user content.
HTMLForge.hxdisabledelt! — Method
hxdisabledelt!(el::HTMLElement, selector::AbstractString) -> HTMLElementAdd an hx-disabled-elt attribute to disable the specified elements during a request.
selector is a CSS selector for elements that should get the HTML disabled attribute while a request is in flight (e.g., "this", "closest button", "#submit-btn").
HTMLForge.hxdisinherit! — Method
hxdisinherit!(el::HTMLElement, attrs::AbstractString) -> HTMLElementAdd an hx-disinherit attribute to disable automatic attribute inheritance for child nodes.
attrs can be "*" to disable all, or a space-separated list of attribute names (e.g., "hx-target hx-swap").
HTMLForge.hxencoding! — Function
hxencoding!(el::HTMLElement, encoding::AbstractString="multipart/form-data") -> HTMLElementAdd an hx-encoding attribute to change the request encoding type.
Set to "multipart/form-data" for file uploads.
HTMLForge.hxext! — Method
hxext!(el::HTMLElement, extensions::AbstractString) -> HTMLElementAdd an hx-ext attribute to enable htmx extensions for this element and its children.
Multiple extensions can be comma-separated (e.g., "response-targets,head-support"). Use "ignore:<ext-name>" to disable an inherited extension.
HTMLForge.hxget! — Method
hxget!(el::HTMLElement, url::AbstractString) -> HTMLElementAdd an hx-get attribute to an HTMLElement in place and return the modified element.
HTMLForge.hxheaders! — Method
hxheaders!(el::HTMLElement, json::AbstractString) -> HTMLElementAdd an hx-headers attribute to include additional headers with the request.
json should be a JSON-formatted string, e.g., "{"X-CSRF-Token": "abc123"}".
HTMLForge.hxhistory! — Function
hxhistory!(el::HTMLElement, value::AbstractString="false") -> HTMLElementAdd an hx-history attribute. Set to "false" to prevent sensitive data on this page from being saved to the browser's history cache (localStorage).
HTMLForge.hxhistoryelt! — Method
hxhistoryelt!(el::HTMLElement) -> HTMLElementAdd an hx-history-elt attribute to mark this element as the snapshot source/target for history navigation (instead of the default body).
HTMLForge.hxinclude! — Method
hxinclude!(el::HTMLElement, selector::AbstractString) -> HTMLElementAdd an hx-include attribute to include values of other elements in the request.
selector is a CSS selector indicating the elements whose values should be included.
HTMLForge.hxindicator! — Method
hxindicator!(el::HTMLElement, selector::AbstractString) -> HTMLElementAdd an hx-indicator attribute specifying which element receives the htmx-request class during a request (to show a loading indicator).
HTMLForge.hxinherit! — Method
hxinherit!(el::HTMLElement, attrs::AbstractString) -> HTMLElementAdd an hx-inherit attribute to explicitly enable attribute inheritance for child nodes when htmx.config.disableInheritance is set to true.
attrs can be "*" to enable all, or a space-separated list of attribute names (e.g., "hx-target hx-swap").
HTMLForge.hxon! — Method
hxon!(el::HTMLElement, event::AbstractString, script::AbstractString) -> HTMLElementAdd an hx-on:<event> attribute to handle events with inline scripts.
The event name supports both htmx events (e.g., "htmx:before-request") and standard DOM events (e.g., "click").
Note: uses the data-hx-on:<event> form for HTML spec compliance.
HTMLForge.hxparams! — Method
hxparams!(el::HTMLElement, value::AbstractString) -> HTMLElementAdd an hx-params attribute to filter the parameters submitted with a request.
Supported values: "*" (all), "none", a comma-separated list of param names, or "not <param-list>" to exclude specific params.
HTMLForge.hxpatch! — Method
hxpatch!(el::HTMLElement, url::AbstractString) -> HTMLElementAdd an hx-patch attribute to an HTMLElement in place and return the modified element.
HTMLForge.hxpost! — Method
hxpost!(el::HTMLElement, url::AbstractString) -> HTMLElementAdd an hx-post attribute to an HTMLElement in place and return the modified element.
HTMLForge.hxpreserve! — Method
hxpreserve!(el::HTMLElement) -> HTMLElementAdd an hx-preserve attribute to keep this element unchanged between requests. Useful for elements like video players that should maintain state across swaps.
Note: the element must have a stable id attribute.
HTMLForge.hxprompt! — Method
hxprompt!(el::HTMLElement, message::AbstractString) -> HTMLElementAdd an hx-prompt attribute that shows a prompt() dialog before submitting the request. The user's response is included in the request via the HX-Prompt header.
HTMLForge.hxpushurl! — Function
hxpushurl!(el::HTMLElement, value::AbstractString="true") -> HTMLElementAdd an hx-push-url attribute to push the request URL into the browser location bar, creating a history entry. Pass "true", "false", or a specific URL.
HTMLForge.hxput! — Method
hxput!(el::HTMLElement, url::AbstractString) -> HTMLElementAdd an hx-put attribute to an HTMLElement in place and return the modified element.
HTMLForge.hxreplaceurl! — Function
hxreplaceurl!(el::HTMLElement, value::AbstractString="true") -> HTMLElementAdd an hx-replace-url attribute to replace the current URL in the browser location bar without creating a new history entry. Pass "true", "false", or a specific URL.
HTMLForge.hxrequest! — Method
hxrequest!(el::HTMLElement, method::Symbol, url::AbstractString) -> HTMLElementAdd an htmx request attribute to an HTMLElement in place and return the modified element.
Valid methods are :get, :post, :put, :patch, and :delete.
HTMLForge.hxrequestconfig! — Method
hxrequestconfig!(el::HTMLElement, value::AbstractString) -> HTMLElementAdd an hx-request attribute to configure various aspects of the request.
value is a JSON-like string, e.g., "timeout:3000, credentials:true" or "noHeaders:true".
HTMLForge.hxselect! — Method
hxselect!(el::HTMLElement, selector::AbstractString) -> HTMLElementAdd an hx-select attribute to select a subset of the response HTML to swap into the target.
HTMLForge.hxselectoob! — Method
hxselectoob!(el::HTMLElement, selectors::AbstractString) -> HTMLElementAdd an hx-select-oob attribute to pick out content for out-of-band swaps.
selectors is a comma-separated list of element IDs (e.g., "#info-details,#other-elt").
HTMLForge.hxswap! — Method
hxswap!(el::HTMLElement, style::AbstractString;
transition::Union{Nothing,Bool}=nothing,
swap::Union{Nothing,AbstractString}=nothing,
settle::Union{Nothing,AbstractString}=nothing,
ignoreTitle::Union{Nothing,Bool}=nothing,
scroll::Union{Nothing,AbstractString}=nothing,
show::Union{Nothing,AbstractString}=nothing,
focusScroll::Union{Nothing,Bool}=nothing) -> HTMLElementAdd an hx-swap attribute to an HTMLElement with optional modifiers.
Arguments
style: The swap style — one of "innerHTML" (default), "outerHTML", "afterbegin", "beforebegin", "beforeend", "afterend", "delete", "none".transition: Whether to use the View Transition API for this swap.swap: A swap delay (e.g. "100ms") between clearing old content and inserting new.settle: A settle delay (e.g. "100ms") between inserting new content and settling it.ignoreTitle: Iftrue, any<title>found in new content will be ignored.scroll:"top"or"bottom"— scroll the target element to its top or bottom.show:"top"or"bottom"— scroll the target element's top or bottom into view.focusScroll: Whether the focused element should be scrolled into view.
HTMLForge.hxswapoob! — Function
hxswapoob!(el::HTMLElement, value::AbstractString="true") -> HTMLElementAdd an hx-swap-oob attribute to mark an element for out-of-band swapping.
The value can be "true" or any valid swap style optionally followed by a CSS selector (e.g., "innerHTML:#target").
HTMLForge.hxsync! — Method
hxsync!(el::HTMLElement, value::AbstractString) -> HTMLElementAdd an hx-sync attribute to control how requests made by different elements are synchronized.
Common values: "closest form:abort", "this:drop", "this:queue first", "this:queue last", "this:queue all", "this:replace".
HTMLForge.hxtarget! — Method
hxtarget!(el::HTMLElement, selector::AbstractString) -> HTMLElementAdd an hx-target attribute to an HTMLElement.
Supported values include standard CSS selectors as well as htmx extended selectors: "this", "closest <selector>", "find <selector>", "next <selector>", "previous <selector>".
HTMLForge.hxtrigger! — Method
hxtrigger!(el::HTMLElement, event::AbstractString; kwargs...) -> HTMLElementAdd an hx-trigger attribute to an HTMLElement with appropriate modifiers and return the modified element.
Arguments
el: The HTML element to add the trigger toevent: The event name (e.g., "click", "mouseenter", "load", "revealed")once::Bool: Whether the trigger should only fire oncechanged::Bool: Whether the trigger should only fire if the value of the element has changeddelay::AbstractString: A time interval (e.g., "1s") to wait before issuing the requestthrottle::AbstractString: A time interval (e.g., "1s") to throttle requestsfrom::AbstractString: A CSS selector to listen for the event on a different elementtarget::AbstractString: A CSS selector to filter the trigger to elements matching the selectorconsume::Bool: Whether the event should be consumed (not propagated to parent elements)queue::AbstractString: Queue strategy when a request is in flight ("first", "last", "all", "none")filter::AbstractString: A JavaScript expression to filter when the trigger fires (without brackets)
HTMLForge.hxvalidate! — Method
hxvalidate!(el::HTMLElement) -> HTMLElementAdd an hx-validate attribute to force elements to validate themselves before a request. This integrates with the HTML5 Validation API.
HTMLForge.hxvals! — Method
hxvals!(el::HTMLElement, json::AbstractString) -> HTMLElementAdd an hx-vals attribute to include additional values with the request.
json should be a JSON-formatted string of name-value pairs, e.g., "{"myVal": "My Value"}".
HTMLForge.intersect_trigger — Method
intersect_trigger(el::HTMLElement;
root::Union{Nothing,AbstractString}=nothing,
threshold::Union{Nothing,Real}=nothing,
once::Bool=true) -> HTMLElementAdd an 'intersect' trigger to an element (fires when element intersects the viewport).
Arguments
root: A CSS selector of the root element for intersectionthreshold: A floating point between 0.0 and 1.0 indicating the amount of intersection needed
HTMLForge.load_trigger — Method
load_trigger(el::HTMLElement; delay::Union{Nothing,AbstractString}=nothing) -> HTMLElementAdd a 'load' trigger to an element, optionally with a delay.
Examples
# Trigger on load
load_trigger(el)
# Trigger on load with delay
load_trigger(el; delay="1s")HTMLForge.parsehtml_snippet — Method
parsehtml_snippet(input::AbstractString; preserve_whitespace=false, preserve_template=false)Parse an HTML snippet into an HTMLElement. This is useful for parsing a snippet of HTML that is not a complete document, such as a <div> tag.
Note: this function is not as robust as parsehtml and may not work for all inputs. Also, the assumption is that the tag is intended to part of the <body> tag.
For scenarios where the snippet is composed from multiple sequential tags, the output will be wrapped in a <div> tag.
HTMLForge.poll_trigger — Method
poll_trigger(el::HTMLElement, interval::AbstractString) -> HTMLElementAdd a polling trigger to an element.
Arguments
interval: The polling interval (e.g., "2s", "500ms")
Examples
# Poll every 2 seconds
poll_trigger(el, "2s")HTMLForge.postorder — Method
postorder(node)Return a post-order depth-first iterator over the tree rooted at node.
HTMLForge.preorder — Method
preorder(node)Return a pre-order depth-first iterator over the tree rooted at node.
HTMLForge.removeclass! — Method
removeclass!(elem::HTMLElement, cls::AbstractString)Removes the class cls from elem.
HTMLForge.revealed_trigger — Method
revealed_trigger(el::HTMLElement; once::Bool=true) -> HTMLElementAdd a 'revealed' trigger to an element (fires when element scrolls into view). By default, this only triggers once.
HTMLForge.setattr! — Method
setattrs!(elem::HTMLElement, name::AbstractString, value::AbstractString)Set the attributes of an element.
HTMLForge.tag — Method
tag(elem::HTMLElement)Get the tag of an element.
HTMLForge.text — Method
text(el::HTMLElement) :: AbstractStringGet the text of an element.
HTMLForge.text — Method
text(t::HTMLText) :: AbstractStringGet the text of a text element.
HTMLForge.validate — Method
validate(::Val{:attr}, value::AbstractString)Validate HTML attribute names.
HTMLForge.validate — Method
validate(::Val{:attr}, value::AbstractString)Validate HTML attribute names.
HTMLForge.validate — Method
validate(::Val{:class}, value::AbstractString)Validate CSS class names.
HTMLForge.validate — Method
validate(::Val{:class}, values::Vector{<:AbstractString})Validate CSS class names.
HTMLForge.@validate — Macro
@validate type valueValidate HTML elements based on their type using compile-time dispatch.
Arguments
type: Symbol indicating what to validate (:attrfor attribute names,:classfor class names)value: The string(s) value to validate
Examples
@validate :attr "class" # Validates an attribute name
@validate :attr ["id", "data-value"] # Validates multiple attribute names
@validate :class "my-class" # Validates a class name
@validate :class ["class1", "class2"] # Validates multiple class namesReturns
Returns true if validation passes, otherwise throws an error.