0

A project I imported into my Eclipse IDE has an HTML file with the following near the top of the file:

<div class="header_logo"><a href="./"   onclick=    javascript: return changePage(0, ''); class="logo"><img     src="images/logo-big.jpg" alt="Noridian" width="169" height="80" /></a></div>

The Eclipse IDE calls out the onclick as being in error: Open quote is expected for attribute "onclick" associated with an element type "a".

May I assume that the onclick should read:

<div class="header_logo"><a href="./"   onclick= "javascript: return changePage(0, '');" class="logo"><img  src="images/logo-big.jpg" alt="Noridian" width="169" height="80" /></a></div>

I am definitely not a Javascript expert but from what I have read, the statement following the onclick= should be surrounded with open quotes.

6
  • 1
    There is no reason to use javascript:. Your first line shows no quotes and your second one does.... so do you actually have quotes? onclick="return changePage(0, '');" Commented Jan 11, 2021 at 20:04
  • @epascarello return doesn't make sense here, does it? Commented Jan 11, 2021 at 20:24
  • @howlger makes perfect sense if you want to cancel the action Commented Jan 11, 2021 at 20:31
  • @epascarello I see. I didn't know that. Thank you for telling me that. Commented Jan 11, 2021 at 21:07
  • epascarello ...Correct ...the first line without quotes causes the warning message "Open quote is expected for attribute "onclick" associated with an element type "a". " ...when I then use quotes ( "javascript: return changePage(0, '');" ) ...the warning goes away ...I am just wondering if the quotes are indeed optional and the warning message is therefore erroneous. Commented Jan 11, 2021 at 22:38

1 Answer 1

1

In HTML the unquoted attribute value syntax is only allowed for values without spaces, single quotes, etc.:

The attribute name, followed by zero or more space characters, followed by a single U+003D EQUALS SIGN character, followed by zero or more space characters, followed by the attribute value, which, in addition to the requirements given above for attribute values, must not contain any literal space characters, any U+0022 QUOTATION MARK characters ("), U+0027 APOSTROPHE characters ('), U+003D EQUALS SIGN characters (=), U+003C LESS-THAN SIGN characters (<), U+003E GREATER-THAN SIGN characters (>), or U+0060 GRAVE ACCENT characters (`), and must not be the empty string.

So yes, the error is shown correctly, as this is not valid HTML without the quotes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.