I’m working on a chatbot where users can talk to the chatbot and I would like to have the conversation logged into a text file. I was thinking grabbing the <div class=”msg-text”>, which represent the conversation the document.getElementByClass(“msg-text”)[0].innerText; which is the chatbot’s response and the document.getElementByClass(“msg-text”)[1].innerText; which is the user’s response and have it to be read into a file.
Tag: getelementsbyclassname
How to use JavaScript to get element by class name and then split commas onto new lines?
Let’s say I have this HTML output: How would I use a simple script to replace the comma and space inside each ‘blog-post-title-link’ class with a line break? So instead of looking like this: John Doe, MD Jane Doe, MD Jane Doe Smith, MD The output would be: John DoeMD Jane DoeMD Jane Doe SmithMD UPDATED NOTE: The names and
Use vanilla javascript to add / remove class to a different element after clicking on another one
I have looked through a number of similar questions but can not find a specific example of one that answers in vanilla JS how to add and remove a class to a different element from the one clicked on. I know it has something to do with setting up a loop and iterating through the elements, but I got lost
Get element inside element by class and ID – JavaScript
Alright, I’ve dabbled in JavaScript before, but the most useful thing I’ve written is a CSS style-switcher. So I’m somewhat new to this. Let’s say I have HTML code like this: How would I change Hello world! to Goodbye world!? I know how document.getElementsByClassName and document.getElementById work, but I would like to get more specific. Sorry if this has been
Iterating over result of getElementsByClassName using Array.forEach
I want to iterate over some DOM elements, I’m doing this: but I get an error: document.getElementsByClassName(“myclass”).forEach is not a function I am using Firefox 3 so I know that both getElementsByClassName and Array.forEach are present. This works fine: Is the result of getElementsByClassName an Array? If not, what is it? Answer No, it’s not an array. As specified in