0

I don't know how to change the value of data-initial-value (highlighted in red in the picture) with in the textarea div. I have tried using .innertext with the input "hi" but you can see that it only changes the inner text and has no effect on the value of data-initial-value. I am working on an extension for Google Meet and would like the type in the chat box and hit send. So whenever something is typed into the chat box, Google Meet sets the value of the input to data-initial-value and not the innerText. So how do I change the value of data-initial-value?

Things I have tried that do not work:

document.querySelector(".KHxj8b").innerText = "hello world";
document.querySelector(".KHxj8b").value = "hello world";

Images Below:

No input in the textbox (highlighted in red)


Input of "hello world" inside textbox (highlighted in red)

UofCcoder
  • 15
  • 1
  • Attributes that start with `data-` are [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes). You can set them in JavaScript using the element's [`setAttribute()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute) method or by using the element's [`dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLOrForeignElement/dataset) property. – Bart Hofland Apr 19 '21 at 16:57
  • 1
    I think you will need to trigger events after setting the `value`. They are likely using one of their js frameworks that uses internal state. Really doubt that just changing that attribute will do much good on it's own – charlietfl Apr 19 '21 at 16:59
  • 1
    @charlietfl . . . Indeed. So this question actually appears to be an [XY problem](https://en.wikipedia.org/wiki/XY_problem). – Bart Hofland Apr 19 '21 at 17:01
  • @BartHofland XY almost definite here – charlietfl Apr 19 '21 at 17:04
  • @charlietfl you are right lmao – UofCcoder Apr 19 '21 at 17:08

3 Answers3

0

You will need to use setAttribute(), since data-initial-value is an attribute of that tag.

document.querySelector(".KHxj8b").setAttribute("data-initial-value", "The value");

Change "The value" to what ever you want it to be.

A5H1Q
  • 544
  • 7
  • 15
Ido Cohen
  • 621
  • 5
  • 16
0

You have to setAttribute('data-initial-value', yourvalue);

0

Use set attribute method: https://www.w3schools.com/jsref/met_element_setattribute.asp

document.querySelector(".KHxj8b").setAttribute("data-initial-value", "The value");

Also if it ain't working and you think you can delete that attribute then use JS to delete it. But it may break a few functionalities

element.removeAttribute(attributename)

Here the element is document.querySelector(".KHxj8b"). and attribute is data-initial-value

Krish Yadav
  • 165
  • 11