Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating dynamic span

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>

like image 436
Asmita Avatar asked Oct 29 '12 09:10

Asmita


People also ask

Can I add CSS to span?

The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute.

Can we use span in HTML?

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.


1 Answers

You can use wrap():

$("<img />").attr({
    id: "image-1",
    src: "/images/flower.png"
}).appendTo("#" + imgContainer).wrap("<span />")
like image 83
VisioN Avatar answered Sep 18 '22 19:09

VisioN