highlighting sentence in paragraph

Discussion in 'JavaScript' started by emike, Mar 28, 2008.

  1. #1
    I need some help highlighting one entire sentence of a paragraph. In the example below, the third sentence will turn red after clicking on the "Click here to check your answer," sentence.

    For example:

    Click here to check your answer.

    November and December are wonderful months for gardening in the south. While residents of northern states are more concerned with preparations for winter, gardeners in southern states can enjoy natural circumstances that enhance their efforts. Football enthusiasts in November and December can enjoy the sport throughout the country. Temperatures in the south are warm enough to grow abundant amounts of flowers and vegetables. Plants and gardeners are relatively free from the pesky bug populations that present problems during the summer. If you enjoy gardening, you'll find November and December good months in the south.


    Any ideas on how to do this? I'm new to javascript. Just need a little help.

    Thanks,
    Mike
     
    emike, Mar 28, 2008 IP
  2. So1

    So1 Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    HTML:
    
    November and December are wonderful months for gardening in the south. 
    While residents of northern states are more concerned with preparations for winter, gardeners in southern states can enjoy natural circumstances that enhance their efforts. <span id="hls">Football enthusiasts in November and December can enjoy the sport throughout the country.</span> 
    Temperatures in the south are warm enough to grow abundant amounts of flowers and vegetables. Plants and gardeners are relatively free from the pesky bug populations that present problems during the summer. 
    If you enjoy gardening, you'll find November and December good months in the south.
    
    Code (markup):
    JS:
    
    document.getElementById('hls').style.backgroundColor = "rgb (255, 0, 0)";
    or
    document.getElementById('hls').style.backgroundColor = "#ff0000";
    
    Code (markup):
    Is that what u need?
     
    So1, Mar 28, 2008 IP
  3. emike

    emike Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much for your response.

    Here’s what I have so far.

    <head>
    ...
    <script type="text/javascript" src="/javascript/prototype.js"></script>
    <script type="text/javascript" src="/javascript/scriptaculous.js?load=effects"></script>
    <script type="text/javascript">
    function handleCheckLinks(e) {
    var activator = e.findElement('a.answerChecker');
    if (!activator)
    return;
    e.stop();
    activator.up('p').previous('p').down('span.answer').highlight();
    }

    document.observe('click', handleCheckLinks);
    </script>
    ...

    <p><a href="#" class="answerChecker">Click here</a> when you are finished.</p>

    <p class="Rightbar_body_green">November and December are
    wonderful months for gardening in the south. While residents
    of northern states are more concerned with preparations for
    winter, gardeners in southern states can enjoy natural
    circumstances that enhance their efforts.
    <span class="answer">Football enthusiasts in November
    and December can enjoy the sport throughout the country.</span>
    Temperatures in the south are warm enough to grow abundant
    amounts of flowers and vegetables. Plants and gardeners are
    relatively free from the pesky bug populations that present
    problems during the summer. If you enjoy gardening, you'll
    find November and December good months in the south.</p>
    </head>

    A few questions:
    1. It doesn’t work if the ‘Click here’ sentence is before the main paragraph.
    2. How do I change the color of the incorrect sentence?
    3. I would also like the answer to remain highlighted after clicking ‘Click here’.

    Please forgive my lack of knowledge. I’m very new to javascript.

    Thanks again,
    Mike
     
    emike, Mar 28, 2008 IP