My code is the following:
const pagedata = {
name: "Value for name",
email: "Value for email",
};
$(".fillvalfromvar").val(pagedata[$(this).attr("id")]);
I need to fill all the elements having the fillvalfromvar
class with the value of the variable pointed to by the element id. For example the HTML is the following:
<input id="name" class="fillvalfromvar" type="text">
<input id="email" class="fillvalfromvar" type="text">
And I’d like to fill those val
s with pagedata["name"]
and pagedata["email"]
, respectively.
But the this
value isn’t pointing to the original element. What should I use instead?