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 3335802
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:03:37+00:00 2026-05-18T00:03:37+00:00

In response to some asynchronous event on the server, I want to update the

  • 0

In response to some asynchronous event on the server, I want to update the class of an HTML node in order to reflect its updated status. I know the id of the node, and the class I want to change it to. What JsCmd do I need to use to update the class? In general, where can I find a good reference on the JsCmd’s and what they do?

A simple example:

case class UpdateClass(id: String, htmlClass: String)

class ClassUpdater extends CometActor {
  override def lowPriority: scala.PartialFunction[scala.Any, scala.Unit] = {
    case UpdateClass(id, htmlClass) =>
      partialUpdate(Noop /* now what? */)
  }

  def render = NodeSeq.Empty
}

So if I had the HTML:

<html><body>
<lift:comet type="ClassUpdater"/>
<div id="foo" class="bar">insert text here</div>
</body></html>

If I sent the message UpdateClass("foo", "baz") to my ClassUpdater, I want the class of my div to change to baz.

  • 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. Editorial Team
    Editorial Team
    2026-05-18T00:03:37+00:00Added an answer on May 18, 2026 at 12:03 am

    Edit: I’ve found a better way to do it. The old code is now more of a blueprint for more complicated stuff.

    Looks like there is a more straightforward way of doing it without jQuery:

    SetElemById("foo", JE.Str("baz"), "className")
    

    which translates to a JavaScript call

    document.getElementById("foo").className = "baz";
    

    Note that JE.Str("baz") can be any JsExp and if you could also do something like

    SetElemById("foo", JE.Str("baz"), "firstChild", "className")
    

    which would change the class of the first child. (See: SetElemById)

    You can have a look at the code for the JsCMD trait for what else is possible with build-in commands.


    In case you want to something more complicated, however, something like this might help you. It sends a jQuery command which will change the class in #oldId to newClass.

      case class ChangeClassAtId(oldId: String, newClass: String) extends JsCmd {
        def toJsCmd = """try {
          $(""" + ("#" + oldId).encJs + """).attr("class", """ + newClass.encJs + """);
        } catch (e) {}"""
      }
    

    Changing all occurrences of a class everywhere is a bit more complicated:

    case class ChangeClass(oldClass: String, newClass: String) extends JsCmd {
        def toJsCmd = """try {
          $(""" + ("." + oldClass).encJs + """).each(function(){
              $(this).addClass(""" + newClass.encJs + """).removeClass(""" + oldClass.encJs + """);
            });
        } catch (e) {}"""
      }
    

    You should use it instead of Noop of course.

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

Sidebar

Related Questions

I have a plist where I would like to save a some response details
I am using a data contract in WCF, but there is some unwanted response
For some reason the facebook crawler is triggering the json response in my rails
There are some double fields in the response have values as NaN, however, i
I got some weird error with response.redirect() and the project wasn't building at all..
I need to select some values from a json response. Im using json.net, fine
As title says for some purpose I need to get the size of request/response
I used Response.Write to write dynamic javascript into a page to test some values
Using hpricot I can get the content of some divs - doc = Hpricot(@response)
For some of HTTP requests from clients, there're very complex business logic in server

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.