Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 143245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:03:54+00:00 2026-05-11T08:03:54+00:00

A list of paragraphs ( <p> ) is given. As soon as the user

  • 0

A list of paragraphs (<p>) is given. As soon as the user clicks on paragraph A the class of paragraph A changes to ‘activated’. Now the user selects paragraph B and all the paragraphs between A and B change their class to ‘activated’.

By clicking on B again, only A remains with the class ‘active’.

By clicking on A the class ‘active’ gets removed on all paragraphs between A and B (including A and B).

It shouldn’t be possible to ‘deactivate’ any paragraph between A and B. The selection between A and B should always be a uninterrupted list of selected paragraphs.

Can anyone give me a hint on how to realize this with Prototype/Scriptaculous? The application is implemented in Rails, so any hint in RJS would even be more appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:03:54+00:00Added an answer on May 11, 2026 at 8:03 am

    OK, in the meantime and with the help of a coworker I came up with an own answer to this problem:

    <script type='text/javascript'>     // holds paragraph A (first selected paragraph)     var a_selected = null;     // holds paragraph B (second selected paragraph)     var b_selected = null;     // holds all 'active' paragraphs     var selected_paras = [];      function class_flipper_init() {         // reset paragraphs A and B         a_selected = null;         b_selected = null;         var paragraphs = $$('#foobar p');         paragraphs.each(function(paragraph, index) {             // if user clicks on a paragraph             paragraph.observe('click', function(event) {                 // if A and B are 'active': reset everything.                 if(b_selected != null) {                     selected_paras.each(function(i) {                         toggleStyle(i);                     })                     a_selected = null                     b_selected = null                     return                 }                 // if A is 'active'                 if(a_selected != null) {                     // if A is 'active' and selected B is below A:                     // select all paragraphs between A and B                     if(a_selected < index) {                         b_selected = index;                         for (var i = a_selected + 1; i <= index; i++ ) {                             toggleStyle(paragraphs[i])                         }                     }                     // if A is 'active' and selected B is above A:                      // select all paragraphs between A and B                     else if(a_selected > index) {                         b_selected = index;                         for (var i = a_selected - 1; i >= index; i-- ) {                             toggleStyle(paragraphs[i])                         }                     }                     // if A == B                     else {                         toggleStyle(paragraph)                         a_selected = null                     }                 }                 // if A is selected                 else {                     a_selected = index;                     toggleStyle(paragraph)                 }             });         });     }      function toggleStyle(paragraph) {         // remove active class         if (paragraph.hasClassName('active')) {             paragraph.removeClassName('active');             selected_paras = selected_paras.without(paragraph)         }          // set active class         else {             paragraph.addClassName('active');             selected_paras.push(paragraph)         }     } </script> 

    class_flipper_init() is called everytime the page (or in my case a certain partial) is loaded.

    Please don’t hesitate to submit a solution written in ‘pure’ RJS or something more elegant. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine an HTML documetn with a long long list of paragraphs. The user scrolls
list of link. required when we click it changes its color i.e highlight active
List<CertMail> lsRecipetNumber = new List<CertMail>(); CertMail class is in data access layer which returns
List<Foo> fooList = Session[foo] as List<Foo>; fooList.Add(bar); Does the call to Add() change the
I want to select a particular list of words in a paragraph containing certain
I've got a list with paragraphs in it, yet it's displaying pretty weird in
I have two models as follows: class Tag(models.Model): # ... class Paragraph(models.Model): tags =
What's a command to list all recent failures in Autosys? I was thinking of
I have written a program to search for a given phrase in a paragraph
I have a list of <p> where some clicks may originate. I understand how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.