|
INTERVIEW QUESTIONS
PROGRAMMING LANGUAGES
HTML
DETAILS
Question: Should I put quotes around attribute values?
Answer: t is never wrong to quote attribute values, and many people recommend quoting all attribute values even when the quotation marks are technically optional. XHTML 1.0 requires all attribute values to be quoted. Like previous HTML specifications, HTML 4 allows attribute values to remain unquoted in many circumstances (e.g., when the value contains only letters and digits). Be careful when your attribute value includes double quotes, for instance when you want ALT text like "the "King of Comedy" takes a bow" for an image. Humans can parse that to know where the quoted material ends, but browsers can't. You have to code the attribute value specially so that the first interior quote doesn't terminate the value prematurely. There are two main techniques:
* Escape any quotes inside the value with " so you don't terminate the value prematurely: ALT="the "King of Comedy" takes a bow". * Use single quotes to enclose the attribute value: ALT='the "King of Comedy" takes a bow'.
Both these methods are correct according to the specification and are supported by current browsers, but both were poorly supported in some earlier browsers. The only truly safe advice is to rewrite the text so that the attribute value need not contain quotes, or to change the interior double quotes to single quotes, like this: ALT="the 'King of Comedy' takes a bow".
|
|
|
Category |
HTML Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 9181 users |
Added on |
9/14/2014 |
Views |
70213 |
Rate it! |
|
|
Question:
Should I put quotes around attribute values?
Answer:
t is never wrong to quote attribute values, and many people recommend quoting all attribute values even when the quotation marks are technically optional. XHTML 1.0 requires all attribute values to be quoted. Like previous HTML specifications, HTML 4 allows attribute values to remain unquoted in many circumstances (e.g., when the value contains only letters and digits). Be careful when your attribute value includes double quotes, for instance when you want ALT text like "the "King of Comedy" takes a bow" for an image. Humans can parse that to know where the quoted material ends, but browsers can't. You have to code the attribute value specially so that the first interior quote doesn't terminate the value prematurely. There are two main techniques:
* Escape any quotes inside the value with " so you don't terminate the value prematurely: ALT="the "King of Comedy" takes a bow". * Use single quotes to enclose the attribute value: ALT='the "King of Comedy" takes a bow'.
Both these methods are correct according to the specification and are supported by current browsers, but both were poorly supported in some earlier browsers. The only truly safe advice is to rewrite the text so that the attribute value need not contain quotes, or to change the interior double quotes to single quotes, like this: ALT="the 'King of Comedy' takes a bow". Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How can I show HTML examples without them being interpreted as part of my document?
|
View Answer
|
|
How can I have two sets of links with different colors?
|
View Answer
|
|
How do I create a link that sends me email?
|
View Answer
|
|
Why is there extra space before or after my table?
|
View Answer
|
|
Why doesn't <TABLE WIDTH="100%"> use the full browser width?
|
View Answer
|
|
Can I use percentage values for <TD WIDTH=...>?
|
View Answer
|
|
How can I use forms for pull-down navigation menus?
|
View Answer
|
|
How can I use tables to structure forms?
|
View Answer
|
|
How can I eliminate the extra space after a </form> tag?
|
View Answer
|
|
How do I set the focus to the first form field?
|
View Answer
|
|
How do I make a form so it can be submitted by hitting ENTER?
|
View Answer
|
|
Do I have to memorize a bunch of tags?
|
View Answer
|
|
How can I check for errors?
|
View Answer
|
|
How do I use forms?
|
View Answer
|
|
How do I center a table?
|
View Answer
|
|
How can I use tables to structure forms?
|
View Answer
|
|
How do I align a table to the right (or left)?
|
View Answer
|
|
Can I nest tables within tables?
|
View Answer
|
|
What is a DOCTYPE? Which one do I use?
|
View Answer
|
|
What is everyone using to write HTML?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All HTML Interview Questions & Answers - Exam Mode /
Learning Mode
|