/    Sign up×
Community /Pin to ProfileBookmark

Comment doesn’t work sometimes

for example –

<img src= “hotdog.jpg” alt=”Problem with Image” <!–name if image fails to load, instead of red X–> width=”20%” title=”working”<!–mouseover name–> />

the browser thinks that the last part is text and displays
width=”20%” title=”working” />

i have the feeling it is an extra ‘ or “, but can’t figure out where.

little help please

to post a comment
HTML

7 Comments(s)

Copy linkTweet thisAlerts:
@cootheadSep 01.2011 — Hi there pratto,

and a warm welcome to these forums. ?

It is not permissible to place html comments within the tag. :eek:

So instead do it like this...
[color=navy]
&lt;!--alt text is displayed if image fails to load, title text is displayed on image hover--&gt;
&lt;img src= "hotdog.jpg" width="20%" alt="Problem with Image" title="working"&gt;
[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@CharlesSep 01.2011 — Hi there pratto,

and a warm welcome to these forums. ?

It is not permissible to place html comments within the tag. :eek:

So instead do it like this...
[color=navy]
&lt;!--alt text is displayed if image fails to load, title text is displayed on image hover--&gt;
&lt;img src= "hotdog.jpg" width="20%" alt="Problem with Image" title="working"&gt;
[/color]

[i]coothead[/i][/QUOTE]
Strictly speaking, all HTML comments exist inside tags and the double dash turns the comment off and on. So &lt;img src= "hotdog.jpg" alt="Problem with Image" --name if image fails to load, instead of red X-- width="20%" title="working"--mouseover name--&gt;However, that's only for HTML and not for XHTML and even then you can expect support to be spotty.
Copy linkTweet thisAlerts:
@cootheadSep 01.2011 — Hi there Charles,

thank you for that insight. ?

I tried your example in html, xhtml and html5 it does work OK, but all fail validation. :eek:

Here is the html code used used for my...
[color=navy]
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div&gt;
&lt;img src= "hotdog.jpg" alt="Problem with Image" --name if image fails to load, instead of red X-- width="20%" title="working" --mouseover name--&gt;
&lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@CharlesSep 01.2011 — Yet you can see those type of comments in the HTML 4.01 DTD. HTML has a bunch of weird things that aren't always supported and often considered not a part of HTML, like the compound closing tags.
Copy linkTweet thisAlerts:
@freedavinSep 02.2011 — It is not permissible to place html comments within the tag.
Copy linkTweet thisAlerts:
@prattoauthorSep 02.2011 — thanks to you both.

i continued to research the problem, and to try different approaches. i did finally find out that comments don't work within tags (at least most of the time). just as you say.

and i came to the same workaround (comment on another line).

but thanks again, and it is nice to know that, as i learn xhtml, i may be able to post a question in this forum and chat with knowledgeable folks.

pat
Copy linkTweet thisAlerts:
@iansane6Sep 02.2011 — I think it should be noted that comments like that are not required in your code. Anyone who doesn't know the purpose of the alt attribute maybe shouldn't even be looking at your code. I do understand the point of trying to comment the code well and I definitely respect and appreciate the effort as some people do a lousy job of it. But I've gone back through a lot of my code and removed obvious comments like that. In order to validate as I'm sure you've already found, the alt attribute must be there for a img according to w3c.

Also, I don't know if anyone cares about IE6 any more but in an effort to make my sites cross browser compatible (IE6,7,8,9,firefox,chrome,safari) I keep the html comments to a minimum and only use them to mark the end of a div or span. IE6 actually has a issue sometimes with this.
[CODE]
<div id="container">
html
</div><!--end container-->
[/CODE]


and has to be changed to this
[CODE]
<div id="container">
html
<!--end container-->
</div>
[/CODE]


If you've ever had to go through code moving comments inside the div tag one at a time to see which one IE6 is choking on causing it to put ghost text at the bottom of the page you know what I mean.

So basically I have developed a practice of minimal comments in the html and put all the display info and scripts in external files so my html is easy to read and doesn't need any explanation.
×

Success!

Help @pratto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...