Adding items to div with title that user can change anytime by clicking on it
Hello i wrote a code that create a new item in card and set its name to
Default Task Name
but i want to add function that allow user to change it anytime when he click on title.
The problem is that user cant edit existing titles but only new created, and i want to make it more simple so when user click button to add it auto focus on title so he can change title before he create a card. I hope I explained it well11 Replies
Daily reminder to not use
var
, use let
or const
. Doesn't answer your question but will help your code qualityty, i forgot
and fixed this issue so dont need help anymore
ā¤ļø
Nice! Do you mind posting your solution so it may help others in the future?
@artusss0 please do post the solution if you can, and mark the post as solved when you have (just add the solved tag)
ohhh ok, i was just closing them
ill post solution in a moment
I added
onclick="editTitle(this)"
to every item do it triggers function to edit title witch param equals to this element, then
on click javascript gets this element and replace with input, when someone click enter or focus on smth other function will execute saveChanges()
and again replace input with normal text
we can also add if (input.value.trim() !== '')
to check if input is not empty so user cant delete title
i still didnt figure out how to trigger editTtile()
just after creating new card but when i do ill add soultionyeah, please don't delete posts, they're here so everyone can learn š
thanks for adding your solution!
just added
editTitle(newItem)
to trigger function and it works fine
now everythink is working correctly as it should ā¤ļø
ye my bad sorry for thatJust for reference, this could also be achieved using the built-in html attribute
contenteditable="true"
without the need to convert the element to an input field.You saved me with this codepen š
I did not know about that
sorry that i didnt post solution before
all good!