Did you know HTML elements can be editable?

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa πΏπ¦. I love writing about JavaScript, HTML and CSS.
Thatβs cool that you showcased this often forgotten attribute. Iβm actually quite familiar with contentenditable as I worked on a project that utilized it to create a transcript editor. When you couple it with Javascript, itβs actually pretty powerful.
Oh nice to hear someone actually using it! So you used it as actual "input" to save values?
Yea thatβs the general gist. We used contenteditable to allow them to make revisions and extract the content with textContent. Behind the scenes we do a bunch of validation and all that good stuff. The final product ended up being fairly robust. But I am biased since I worked on it π
Alyssa Holland Sounds cool! Awesome work Alyssa, thanks for noting this, it's good that people see use-cases of this element
Hi! Interesting article.
Sorry for my lack of knowledge but could you give me some examples in which this feature can be useful?
Thanks for sharing!
I personally wouldn't recommend this option for many adventures, BUT it can be useful to make something like a visual character tester!
So imagine you have an email or website and content creators are able to write content, you tell them, keep lines at 250 chars. It would be cooler if they can just see how it would actually look right. In this case contenteditable is a good option.
If they actually need a wysywg editor not, if they need to save the data, not.
It's a thin line, but there are some good use-cases for it.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

This is one of the HTML options you don't see often, but are actually really cool.
There is an HTML attribute called contenteditable, and it allows HTML elements to become editable π.
Let me show you how it looks on this Codepen. (Click any text!)
We can simply make an element editable by adding the contenteditable tag.
<div class="container">
<h1 contenteditable="true">Welcome click me π―</h1>
<p contenteditable="true">
Did you know you can click me to edit my content?<br />
Even big paragraphs π
</p>
<a contenteditable="true" href="#">View the full article</a>
</div>
It can have three values:
contenteditable="true" ~ We can change the contentcontenteditable="false" ~ Not able to change itcontenteditable="inherit" ~ What ever the parent hasOf course, this is cool, but it doesn't do much on its own, we can actually capture these changes with JavaScript.
Let's bind an event listener to the input event for each contenteditable tag.
var contents = document.querySelectorAll('[contenteditable]');
for (let content of contents) {
content.addEventListener('input', function() {
console.log('input changed to: ' + content.innerHTML);
});
}
Since this is a native HTML tag, it has amazing support!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter