How can I create dynamic tags?
$("<img />").attr({
id: "image-1",
src: "/images/flower.png",
}).appendTo("#" + imgContainer);
It will create <img src="/images/flower.png" id="image-1" />
I want to create <span>
tag around <img>
tag.
i.e. <span><img src="/images/flower.png" id="image-1" /></span>
The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.
You can use the HTML span tag as a container to group inline elements together so you can style or manipulate them with JavaScript. In this article, I will show you how to use the span tag to make a certain part of your content distinct from the rest. Then you should be able to start using it in your coding projects.
You can use wrap()
:
$("<img />").attr({
id: "image-1",
src: "/images/flower.png"
}).appendTo("#" + imgContainer).wrap("<span />")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With