You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm taking advantage of the auto-updating title on swap https://htmx.org/docs/#swap-options, this works great but trying to get the value of the updated title document.title doesn't seems stray forward.
The only "reliable" way to obtains the updated value is by adding a timeout, preferably, on the event htmx:afterSettle
Am i missing something ?
Here is the following very basic example :
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The title before load</title>
</head>
<body>
<div hx-get="fragment.html" hx-trigger="load">Default content</div>
</body>
<script src="https://unpkg.com/htmx.org@1.9.11"></script>
<script>
htmx.on("htmx:afterOnLoad", function (evt) {
console.log("From afterOnLoad: " + document.title) // From afterOnLoad: The title before load
console.log(document.querySelector("title")) // <title>The title from the fragment</title>
console.log(document.querySelector("title").text) // The title before load
});
htmx.on("htmx:afterSettle", function (evt) {
console.log("From afterSettle: " + document.title) // From afterSettle: The title before load
console.log(document.querySelector("title")) // <title>The title from the fragment</title>
console.log(document.querySelector("title").text) // The title before load
setTimeout(function() {
console.log("From afterSettle timeout 10: " + document.title) // From afterSettle timeout 10: The title from the fragment
}, 10);
});
</script>
</html>
fragment.html
<title>The title from the fragment</title>
<h1>Hello world !</h1>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I'm taking advantage of the auto-updating title on swap https://htmx.org/docs/#swap-options, this works great but trying to get the value of the updated title
document.title
doesn't seems stray forward.The only "reliable" way to obtains the updated value is by adding a timeout, preferably, on the event
htmx:afterSettle
Am i missing something ?
Here is the following very basic example :
index.html
fragment.html
Beta Was this translation helpful? Give feedback.
All reactions