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

  • Home
  • SEARCH
  • 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'm trying to generate a JSON response that includes some HTML. Thus, I have
I'm refactoring some client-server code and it uses the terms Response, Result & Reply
In my app (node / express / redis), I use some code to update
I am writing the data to the output browser using Response.write(some byte arrary) Response.ContentType
I am using a data contract in WCF, but there is some unwanted response
I got some weird error with response.redirect() and the project wasn't building at all..
I need debug some old code that uses a Hashtable to store response from
I'm doing some straight up asynchronous calls from javascript using the XMLHTTPRequest object. On
For some of HTTP requests from clients, there're very complex business logic in server
When I perform an asynchronous request with jQuery Ajax, sometimes the response is returned

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.