Sign up and we'll send you the best freelance opportunities straight to
your inbox.
We're building the largest freelancing marketplace for people like you.
A custom data-posted-date attribute on an <article>.
The attribute value is not visible, but is readable by JavaScript.
Early life of Van Gogh
Van Gogh returned to Etten in April 1881 for an extended stay
with his parents. He continued to draw, often using his neighbors
as subjects. In August 1881, his recently widowed cousin, Cornelia
Vos-Stricker, daughter of his mother's older sister arrived for
a visit.
He was thrilled and took long walks with her. Cornelia was seven
years older than he was and had an eight-year-old son. Van Gogh
surprised everyone by declaring his love to her and proposing marriage.
She refused with the words: "nooit, neen, nimmer" (nay, no, never).
<article data-posted-date="Dec 19, 2020">
<h2>Early life of Van Gogh</h2>
<p>
Van Gogh returned to Etten in April 1881 for an extended stay
with his parents. He continued to draw, often using his neighbors
as subjects. In August 1881, his recently widowed cousin, Cornelia
Vos-Stricker, daughter of his mother's older sister arrived for
a visit.
</p>
<p>
He was thrilled and took long walks with her. Cornelia was seven
years older than he was and had an eight-year-old son. Van Gogh
surprised everyone by declaring his love to her and proposing marriage.
She refused with the words: "nooit, neen, nimmer" (nay, no, never).
</p>
</article>
A custom data-posted-date attribute on an <article>.
Clicking the button will display the posted date value.
Early life of Van Gogh
Van Gogh returned to Etten in April 1881 for an extended stay
with his parents. He continued to draw, often using his neighbors
as subjects. In August 1881, his recently widowed cousin, Cornelia
Vos-Stricker, daughter of his mother's older sister arrived for
a visit.
He was thrilled and took long walks with her. Cornelia was seven
years older than he was and had an eight-year-old son. Van Gogh
surprised everyone by declaring his love to her and proposing marriage.
She refused with the words: "nooit, neen, nimmer" (nay, no, never).
<article data-posted-date="Jan 4, 2021" id="myarticle">
<h2>Early life of Van Gogh</h2>
<p>
Van Gogh returned to Etten in April 1881 for an extended stay
with his parents. He continued to draw, often using his neighbors
as subjects. In August 1881, his recently widowed cousin, Cornelia
Vos-Stricker, daughter of his mother's older sister arrived for
a visit.
</p>
<p>
He was thrilled and took long walks with her. Cornelia was seven
years older than he was and had an eight-year-old son. Van Gogh
surprised everyone by declaring his love to her and proposing marriage.
She refused with the words: "nooit, neen, nimmer" (nay, no, never).
</p>
</article>
<br/>
<button onclick="show();">Show data</button>
<script>
let show = () => {
let element = document.getElementById("myarticle");
alert("Posted date = " + element.getAttribute('data-posted-date'));
}
</script>
Code explanation
The <article> tag is assigned a data-posted-date attribute.
The data-posted-date attribute specifies when the article was posted.
Button clicks are handled by the onclick event.
Onclick invokes a JavaScript function that extracts and displays the posted date.
Note: The posted date displays very quickly without server call.
Sign up and we'll send you the best freelance opportunities straight to
your inbox.
We're building the largest freelancing marketplace for people like you.