displaying html markup under html alt of img


I want to display a simple html markup (a div with some content of <p>) on image hover and alt seems not working properly. Any way to achieve this?

Note that i need to write the alt content in backend of .NET

 string rawimage =
                                                    "<img data-index='{0}' src='images/category{0}.png' alt='{1}' style='{2}' />",
                                                    "1", myPopupText, "margin-right:4px");

Open in new window

Any way? Or a way with less pain?
LVL 12
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brandon LyonSenior Frontend DeveloperCommented:
That is not what an alt tag is for and it wouldn't work. If you need hover events on the tag you have two options. You can append HTML using CSS content or you can do it using javascript.

The alt tag is for using text only to convey what the image is about. If people can't see the image then they need to know what was there. This is valid for search engines, people with accessibility issues, and when browser/server issues prevent viewing the file.
"title" is the attribute you're looking for, that will add a tooltip to the image when a user hovers over it.
Note that you can't include markup, just simple text.

And FYI, the article above on appending html is actually wrong.  before and after pseudo elements don't actually append before or after the tag itself, they append before or after the content inside the tag.

So elements like img that can't have child elements, before and after will do nothing on most browsers.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brandon LyonSenior Frontend DeveloperCommented:
Ah yes, you're correct, I forgot that certain tags such as IMG will not render CSS before and after content.
Would make life SO much easier if they would ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.