Let's say I have var x = "<input type='number' />". So that's a string. What I want is set a value to that input and in the end, get a string like this:
var y = "<input type='number' value='some value' />"
I have tried different methods but none of them worked the way I wanted. I have tried this:
function myFunction(){
$(x).val(5)
console.log(x)
//I get an object array
}
I do not want to append the element to the DOM, just want the HTML string
using $(x).val()the element needs to be attached to DOM. Try attaching it to body or some element in page abd then execute this code. It should work.