Andor Nagy
Andor Nagy

Reputation: 174

Adding HTML after each IMG tag on the page

I'm trying to add additional html after each image on the page. But, for some reason, it doesn't accept the 'img' tag. If I put 'p' tag, it works, but not for images.

$("img").append("Some text");

Any idea why this is or what am I doing wrong?

Upvotes: 0

Views: 70

Answers (2)

kidA
kidA

Reputation: 1377

Use after('Some text') instead of append('Some text').

append() method puts the content inside the specified element whereas after() puts the content after the specified element.

Upvotes: 2

Venkata Krishna
Venkata Krishna

Reputation: 15112

Use .after() instead

$("img").after("Some text");

.append() puts your string within the img tag but .after() puts it after the img tag

Upvotes: 5

Related Questions