HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 14. JAVASCRIPT AND AJAX 153


14.4.6 Indexed Content


JavaScript can create content, but such content is not indexed by search
engines. Use static HTML for any content that you want to be seen by
search engines.


14.5 Try It: More or Less (Hide and Reveal)


To extend your skills, here is some simple JavaScript you can use to hide or
reveal content.


This is useful when you have lengthy content available, but you only want
to show the first few lines in case the user is not interested. They can click
on[more]for the rest of the content.


It could also be useful for sample test questions, where the question is shown
but the answer is hidden until the user is ready to see it.


Here we use it to show a well-worn joke, where the punch line is revealed on
demand.


Why did the chicken cross the road?

[answer]

HTML Details:


Theptag identifies a paragraph.


Theutag causes[answer]and[hide]to be underlined. You could use
spanor any other tag.


Theidattribute designates an ID for the paragraph. JavaScript will use
that ID to find and modify that paragraph.


Thehiddenattribute designates the paragraph as initially hidden. JavaScript
can be used to reveal it.


Theonclickattribute specifies a bit of JavaScript that will be carried out
when the mouse is clicked on the target.

Free download pdf