How do I add html link to image title - html

I'm actually needing to include html links in the longdesc attribute. I've altered prettyphoto to use longdesc instead of title for images, but I need to include html links in those descriptions. I know it's possible with code for characters, I just don't remember what those are.
Thanks

This can be done with the longdesc attribute:
<img src="theimage.png" longdesc="thedescription.html" />
And then, in thedescription.html:
Link
One alternative way to do this is by using an OBJECT element, as follows:
<OBJECT data="theimage.png" type="image/png">
Link
</OBJECT>
Also, since you asked for it, here is how to convert html entities automatically in jquery:
$('<div/>').text('Some Link').html();
// the above evaluates to <a href="link.html">Some Link</a>

I'm not sure if this is what you're looking for, but you can use Walter Zorn's wz_tooltip to show a tooltip with any kind of content.
And example of use:
<img src="theimage.png" onmouseover="Tip('<a href=\'http://test.com/\'>Link</a>');" onmouseout="UnTip();">

The longdesc attribute is an URI, not a place to add code. In other words, you'll need to create a page that the longdesc links to. This page is where you'll make a thorough description of what's on the image.

Are you looking for the html entities?
If so, these are what you are looking for:
> = >
< = <
" = "
' = '

Related

How to use a link as image title in html

I made attempt and tried to find my goal But I couldn't and found solution like this that didn't benefit for me!
I have <img src="url" title="ali.com"> I want to make ali.com a link. I used
title=ALI.com but doesn't work! any way?
The title attribute accepts only plain text, you cannot have any markup there.
If you want a tooltip with a link inside (and I'd urge you not to as it is a difficult UI to use), then you'll need to build the whole thing with JavaScript and DOM.
Above answers suffices your requirement, but specific to your use case :
<img src="image url" title="ali.com"/>
You can use url as a title (google.com?d=1&e=2 this is string)
You need to run little js code to achieve final goal
put something like this html
<a class="mylink"> <img title="blahblah" scr =""></img></a>
and you can get title string by
yourtitlestring = $(".mylink img").attr("title")
and now you can set href of link
$(".mylink").setAttribute("href", yourtitlestring);

Is it possible to only style part of an image's alt text?

Basically I want something like this, <img src="doesntexist.png alt="Image does <b>Not</b> exist" />.
Edit
Thanks for the info, but I was hoping to accomplish this without JavaScript.
You can't do what you're asking with traditional HTML.
The alt attribute is defined in a set of tags (namely, img, area and optionally for input and applet) to allow you to provide a text equivalent for the object.
http://www.w3.org/QA/Tips/altAttribute
Alt attributes are used to display a text description of an image whenever the image is not available, is not displayed by the browser, or the image cannot be seen by the user. Some users can be blind, color-blind, or low-sighted. The alt attribute is used in such cases to aid users by describing the intent of the image.
You might want to look into something like a tooltip. With tooltips you can customize the style and how they appear to the end user. There are a bunch of them out there. One example is jQuery's Tooltip: http://jqueryui.com/tooltip/#custom-style
Unfortunately no. It can however be replicated to allow markup with Javascript.
function altContent(img) {
var alt = document.createElement('div');
alt.innerHTML = img.getAttribute('alt');
img.parentNode.replaceChild(alt, img);
}
Then just add the attribute onerror to the image, like so.
<img src="doesntexist.png alt="Image does <b>Not</b> exist" onerror="altContent(this)" />
JSFiddle Example
Cleaner Solution

HTML codes inside alt tags

Is it ok to put html codes inside alt tags?
I have a slider that uses alt tags for description. In order style the description, I have to put html codes.
My problem is I dont know if it will harm SEO or any other things to consider..
HTML markup is not valid for the contents of the alt attribute. If you need a fancy dialog ox you can easilt accomlish this with JavaScript and maye even plain old CSS. That way your code is valid and you don't run into any potential SEO issues.
Yes, you can use <img src=foo alt="<i>Hello</i> world">. I don’t see any reason why anyone would, but it’s valid. The alt attribute would then be rendered literally, because it’s an attribute value; no HTML tags are recognized there.
The rendering of alt tag values may or may not be affected by style sheets and markup around the tag. If you write <b><img src=foo alt="<i>Hello</i> world"></b>, then advanced browsers will display <i>Hello</i> world in bold face (but not in italic), when they do not display the image. (The “tooltip” part of the handling of alt attributes is a different issue, unstyleable, and generally not present in any modern browser.)
To use just an attribute that carries some text to be displayed via JavaScript, data-* attributes are a much better approach, as Baptiste Placé points out in his answer. It is technically possible to use alt for that, but this would cause odd things when the image is not displayed (at least temporarily, due to delays) ant the alt text is used in its stead.
Moreover, search engines are known to play attention to alt attribute values, so they should not contain anything that is nonsensical when considering the attribute’s defined role (to provide an alternative text to be used when the image is not shown).
In order to style the description, you need CSS; HTML is for defining a document's structure.
You should not use the alt attribute for your slider, use your own property instead with the data-* attributes. More info on the data attribute : http://www.marcofolio.net/webdesign/html5_data-_attributes_are_great_and_you_know_it.html
You should make this kind of html (using data-longdescr, but use any data-something you like) :
<img src="/img/pic.jpg" alt="Jumping over a fence" data-longdescr="<b>Jumping</b> over a fence" />
Beware of quotes thought, they must be escaped !
Markup won't work on an alt attribute.
I would put all the description tags inside a CSS class. Then, style the class separately.
I think you've all misunderstood the question, OP is asking if it's possible to insert html in to an alt tag because he wanted to style the output text as he was using it as descriptive text overlaying his slides. I've run in to the same problem and discovered it is possible to insert html in to alt tags. This is very handy since I'm using a Wordpress lightbox plugin that turns every picture link on my page in to part of a slideshow and outputs the alt text as descriptive text over each image.
If I could only enter plain text then the styling for my descriptions would have been very limited and I wouldn't be able add in awesome things like links:
<img alt="<?php echo "Title" . "Lorem Ipsum dolor" . "<a href='http://www.google.com'>View Website</a>"; ?> " src="<?php echo $img; ?>">
I'm using php to insert the markup though you can also use plain html
alt="<h3>Title</h3><p>Lorem Ipsum dolor</p><a href='http://www.google.com'>View Website</a>"
Which outputs:
Title
Lorem Ipsum dolor
View Website
I'm not sure if this good for SEO but it's definitely handy and something I didn't know was possible until now.

a link with an <a> tag?

I need a link within an tag as follows:
<span><a data-description="TITLE - See more here" class="bullet" tabindex="-1"</a></span>
How can I have a link on the 'see more here' part?
Is this even possible?
Thanks
The "data-description" attribute is by definition, without any universal semantic meaning (any attribute beginning in "data-"). It might be used by some JavaScript library to add a tooltip, but the only built-in browser tooltip is the "title" attribute which your example is not using (and that does not support HTML, only text). You need to use some library like http://docs.jquery.com/Plugins/Tooltip

Does the content property exist in html

Below is some html I found in this jquery tooltip tutorial, the contents inside of content"" show up in the tooltip using javascript. I have never seen the content propert befre, I search on W3schools.com but and google but could not find anything about it. Is this a valid property?
Image Tooltip
sorry If I am overlooking this, I searched but just briefly, didn't look too much before asking this.
If you need to put custom attributes into an element, then use the html5 data- attributes.
Shamelessly copied from John Resig:
<li class="user" data-name="John Resig" data-city="Boston"
data-lang="js" data-food="Bacon">
<b>John says:</b> <span>Hello, how are you?</span>
</li>
This is most likely a custom attribute that the jQuery tooltip creators made up to hold the text for the tooltip. This is unfortunately a common practice with many jQuery plugins (although most put stuff like this in the rel="" attribute instead).
The downside of this is that if you are concerned with validatiing your HTML, this will cause that to fail.
The upside is that browsers will ignore attributes that they do not expect, so it will not affect the rendering of the page.
The proper place for this would be the title="" attribute, but without the extra HTML markup in the value (<span> in this case).
If you must have the extra markup, be sure to encode it:
title=">span<Image Title</span&gt"
But, be aware that if the Javascript fails, the user will see this encoded text as the built-in, browser-rendered tooltip.
Based on my initial searches on w3c, it seems that there is not such attribute "content" for a tag. The "content" attribute is for meta tag only. For tooltips you would use the "title" attribute. Also, I don't think html is allowed in a title attribute.
Image Tooltip
The content attribute doesn't exist. For tooltips you can use the title attribute (which works on alot of tags).
I thinks some browsers also use the alt attribute for tooltips on img tags, but this isn't the intended purpose of alt.