API Reference

This page contains auto-generated documentation for all public symbols with docstrings in HTMLForge.

All Documented Symbols

Base.getindexMethod
getindex(elem::HTMLElement, key::Union{AbstractString, Symbol})

Get the attribute with the given key from an element.

source
Base.getindexMethod
getindex(elem::HTMLElement, i::Int)

Get the ith child of an element.

source
Base.lengthMethod
length(elem::HTMLElement)

Get the length of elem's children.

source
Base.push!Method
push!(elem::HTMLElement, val::HTMLElement)

Push a child onto an element.

source
Base.setindex!Method
setindex!(elem::HTMLElement, val::AbstractString, key::Union{AbstractString, Symbol})

Set the attribute with the given key on an element.

source
Base.setindex!Method
setindex!(elem::HTMLElement, val::HTMLElement, i::Integer)

Set the ith child of an element.

source
HTMLForge.applyif!Method
applyif!(condition::Function, f!::Function, doc::HTMLDocument)

Apply f! to all elements (nested included) in doc for which condition is true.

source
HTMLForge.applyif!Method
applyif!(condition::Function, f!::Function, elem::HTMLElement)

Apply f! to all elements (nested included) in elem for which condition is true.

source
HTMLForge.attributevalidationMethod
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.

source
HTMLForge.attrsMethod
attrs(elem::HTMLElement) :: Dict{String, String}

Get the attributes of an element.

source
HTMLForge.findfirstMethod
findfirst(f::Function, doc::HTMLDocument) :: Union{HTMLElement, Nothing}

Find the first (PreOrderDFS) element in doc for which f is true.

source
HTMLForge.findfirstMethod
findfirst(f::Function, elem::HTMLElement) :: Union{HTMLElement, Nothing}

Find the first (PreOrderDFS) element in elem for which f is true.

source
HTMLForge.getattrFunction
getattr(elem::HTMLElement, name::AbstractString, default=nothing) :: Union{String, Nothing}

Get the value of an attribute of an element or default if not present.

source
HTMLForge.getbyidMethod
getbyid(doc::HTMLDocument, id::AbstractString) :: Union{HTMLElement, Nothing}

Get the element with the given id from doc.

source
HTMLForge.getbyidMethod
getbyid(elem::HTMLElement, id::AbstractString) :: Union{HTMLElement, Nothing}

Get the element with the given id from elem.

source
HTMLForge.hasattrMethod
hasattr(elem::HTMLElement, name::AbstractString) :: Bool

Check whether an element has an attribute.

source
HTMLForge.hasclassMethod
hasclass(elem::HTMLElement, cls::AbstractString)

Returns true if elem has the class cls.

source
HTMLForge.hxattr!Method
hxattr!(el::HTMLElement, attr::Union{AbstractString,Symbol}, value::AbstractString) -> HTMLElement

Set an arbitrary htmx attribute on an HTMLElement in place. The data-hx- prefix is added automatically.

source
HTMLForge.hxboost!Function
hxboost!(el::HTMLElement, value::AbstractString="true") -> HTMLElement

Add an hx-boost attribute to progressively enhance links and forms to use AJAX.

source
HTMLForge.hxconfirm!Method
hxconfirm!(el::HTMLElement, message::AbstractString) -> HTMLElement

Add an hx-confirm attribute that shows a confirm() dialog before issuing the request.

source
HTMLForge.hxdelete!Method
hxdelete!(el::HTMLElement, url::AbstractString) -> HTMLElement

Add an hx-delete attribute to an HTMLElement in place and return the modified element.

source
HTMLForge.hxdisable!Method
hxdisable!(el::HTMLElement) -> HTMLElement

Add an hx-disable attribute to prevent htmx from processing this element and its children. Useful for including untrusted user content.

source
HTMLForge.hxdisabledelt!Method
hxdisabledelt!(el::HTMLElement, selector::AbstractString) -> HTMLElement

Add 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").

source
HTMLForge.hxdisinherit!Method
hxdisinherit!(el::HTMLElement, attrs::AbstractString) -> HTMLElement

Add 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").

source
HTMLForge.hxencoding!Function
hxencoding!(el::HTMLElement, encoding::AbstractString="multipart/form-data") -> HTMLElement

Add an hx-encoding attribute to change the request encoding type.

Set to "multipart/form-data" for file uploads.

source
HTMLForge.hxext!Method
hxext!(el::HTMLElement, extensions::AbstractString) -> HTMLElement

Add 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.

source
HTMLForge.hxget!Method
hxget!(el::HTMLElement, url::AbstractString) -> HTMLElement

Add an hx-get attribute to an HTMLElement in place and return the modified element.

source
HTMLForge.hxheaders!Method
hxheaders!(el::HTMLElement, json::AbstractString) -> HTMLElement

Add an hx-headers attribute to include additional headers with the request.

json should be a JSON-formatted string, e.g., "{"X-CSRF-Token": "abc123"}".

source
HTMLForge.hxhistory!Function
hxhistory!(el::HTMLElement, value::AbstractString="false") -> HTMLElement

Add an hx-history attribute. Set to "false" to prevent sensitive data on this page from being saved to the browser's history cache (localStorage).

source
HTMLForge.hxhistoryelt!Method
hxhistoryelt!(el::HTMLElement) -> HTMLElement

Add an hx-history-elt attribute to mark this element as the snapshot source/target for history navigation (instead of the default body).

source
HTMLForge.hxinclude!Method
hxinclude!(el::HTMLElement, selector::AbstractString) -> HTMLElement

Add 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.

source
HTMLForge.hxindicator!Method
hxindicator!(el::HTMLElement, selector::AbstractString) -> HTMLElement

Add an hx-indicator attribute specifying which element receives the htmx-request class during a request (to show a loading indicator).

source
HTMLForge.hxinherit!Method
hxinherit!(el::HTMLElement, attrs::AbstractString) -> HTMLElement

Add 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").

source
HTMLForge.hxon!Method
hxon!(el::HTMLElement, event::AbstractString, script::AbstractString) -> HTMLElement

Add 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.

source
HTMLForge.hxparams!Method
hxparams!(el::HTMLElement, value::AbstractString) -> HTMLElement

Add 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.

source
HTMLForge.hxpatch!Method
hxpatch!(el::HTMLElement, url::AbstractString) -> HTMLElement

Add an hx-patch attribute to an HTMLElement in place and return the modified element.

source
HTMLForge.hxpost!Method
hxpost!(el::HTMLElement, url::AbstractString) -> HTMLElement

Add an hx-post attribute to an HTMLElement in place and return the modified element.

source
HTMLForge.hxpreserve!Method
hxpreserve!(el::HTMLElement) -> HTMLElement

Add 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.

source
HTMLForge.hxprompt!Method
hxprompt!(el::HTMLElement, message::AbstractString) -> HTMLElement

Add 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.

source
HTMLForge.hxpushurl!Function
hxpushurl!(el::HTMLElement, value::AbstractString="true") -> HTMLElement

Add 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.

source
HTMLForge.hxput!Method
hxput!(el::HTMLElement, url::AbstractString) -> HTMLElement

Add an hx-put attribute to an HTMLElement in place and return the modified element.

source
HTMLForge.hxreplaceurl!Function
hxreplaceurl!(el::HTMLElement, value::AbstractString="true") -> HTMLElement

Add 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.

source
HTMLForge.hxrequest!Method
hxrequest!(el::HTMLElement, method::Symbol, url::AbstractString) -> HTMLElement

Add an htmx request attribute to an HTMLElement in place and return the modified element.

Valid methods are :get, :post, :put, :patch, and :delete.

source
HTMLForge.hxrequestconfig!Method
hxrequestconfig!(el::HTMLElement, value::AbstractString) -> HTMLElement

Add 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".

source
HTMLForge.hxselect!Method
hxselect!(el::HTMLElement, selector::AbstractString) -> HTMLElement

Add an hx-select attribute to select a subset of the response HTML to swap into the target.

source
HTMLForge.hxselectoob!Method
hxselectoob!(el::HTMLElement, selectors::AbstractString) -> HTMLElement

Add 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").

source
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) -> HTMLElement

Add 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: If true, 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.
source
HTMLForge.hxswapoob!Function
hxswapoob!(el::HTMLElement, value::AbstractString="true") -> HTMLElement

Add 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").

source
HTMLForge.hxsync!Method
hxsync!(el::HTMLElement, value::AbstractString) -> HTMLElement

Add 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".

source
HTMLForge.hxtarget!Method
hxtarget!(el::HTMLElement, selector::AbstractString) -> HTMLElement

Add 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>".

source
HTMLForge.hxtrigger!Method
hxtrigger!(el::HTMLElement, event::AbstractString; kwargs...) -> HTMLElement

Add an hx-trigger attribute to an HTMLElement with appropriate modifiers and return the modified element.

Arguments

  • el: The HTML element to add the trigger to
  • event: The event name (e.g., "click", "mouseenter", "load", "revealed")
  • once::Bool: Whether the trigger should only fire once
  • changed::Bool: Whether the trigger should only fire if the value of the element has changed
  • delay::AbstractString: A time interval (e.g., "1s") to wait before issuing the request
  • throttle::AbstractString: A time interval (e.g., "1s") to throttle requests
  • from::AbstractString: A CSS selector to listen for the event on a different element
  • target::AbstractString: A CSS selector to filter the trigger to elements matching the selector
  • consume::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)
source
HTMLForge.hxvalidate!Method
hxvalidate!(el::HTMLElement) -> HTMLElement

Add an hx-validate attribute to force elements to validate themselves before a request. This integrates with the HTML5 Validation API.

source
HTMLForge.hxvals!Method
hxvals!(el::HTMLElement, json::AbstractString) -> HTMLElement

Add 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"}".

source
HTMLForge.intersect_triggerMethod
intersect_trigger(el::HTMLElement; 
                 root::Union{Nothing,AbstractString}=nothing,
                 threshold::Union{Nothing,Real}=nothing,
                 once::Bool=true) -> HTMLElement

Add an 'intersect' trigger to an element (fires when element intersects the viewport).

Arguments

  • root: A CSS selector of the root element for intersection
  • threshold: A floating point between 0.0 and 1.0 indicating the amount of intersection needed
source
HTMLForge.load_triggerMethod
load_trigger(el::HTMLElement; delay::Union{Nothing,AbstractString}=nothing) -> HTMLElement

Add 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")
source
HTMLForge.parsehtml_snippetMethod
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.

source
HTMLForge.poll_triggerMethod
poll_trigger(el::HTMLElement, interval::AbstractString) -> HTMLElement

Add a polling trigger to an element.

Arguments

  • interval: The polling interval (e.g., "2s", "500ms")

Examples

# Poll every 2 seconds
poll_trigger(el, "2s")
source
HTMLForge.revealed_triggerMethod
revealed_trigger(el::HTMLElement; once::Bool=true) -> HTMLElement

Add a 'revealed' trigger to an element (fires when element scrolls into view). By default, this only triggers once.

source
HTMLForge.setattr!Method
setattrs!(elem::HTMLElement, name::AbstractString, value::AbstractString)

Set the attributes of an element.

source
HTMLForge.@validateMacro
@validate type value

Validate HTML elements based on their type using compile-time dispatch.

Arguments

  • type: Symbol indicating what to validate (:attr for attribute names, :class for 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 names

Returns

Returns true if validation passes, otherwise throws an error.

source