Wednesday, April 17, 2019

Jquery: how to create an element and set attribute at the same time

Example:

var image = $('<img>', { src: `img/${pokenumber}.png` })[0];


or

var image = $('<img>').attr('src', `img/${pokenumber}.png`)[0];

Reference:

https://stackoverflow.com/questions/22886101/jquery-create-a-new-element-with-data-html-attribute



No comments:

Post a Comment