How can I set values of HTML input elements using jQuery? | Experience Community
Skip to main content
Question

How can I set values of HTML input elements using jQuery?

  • Jul 19, 2023 1:26 PM UTC
  • 2 replies
  • 206 views

Forum|alt.badge.img+4

What jQuery syntax works for setting values of HTML input elements?

2 replies

Forum|alt.badge.img+4
  • Author
  • Level 3 ●●●
  • Jul 19, 2023 1:37 PM UTC

For the exemplary HTML input element below the issue seems to be shadow DOM https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM . Instead of being accessible as usual the value of the input element is wrapped into a shadow DOM + div element.



 


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • Jul 19, 2023 1:42 PM UTC

Above what you have highlighted, the input has an ID. This can be used to set the value of the input with jQuery. Try adding the below to the question’s JavaScript in the OnReady section:

var qid = this.questionId;
var input1 = document.getElementById("QR~"+qid+"~1~1");
jQuery(input1).val("44");