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

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

  • July 19, 2023
  • 2 replies
  • 169 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 ●●●
  • July 19, 2023

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 ●●●●●●●●
  • July 19, 2023

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");