Search code examples
ajaxlift

Replace content by class via AJAX


With lift, if we want to replace the content of some DOM, we can use SetHtml if we know the ID of the DOM:

SetHtml(domID, Text("new text"))

But SetHtml only accepts id, what if I want to find DOMs by class?

SetHtml(".message", Text("new message"))

It can't work(of course), what should I do now?


Solution

  • if you want to use scala jquery DLS, maybe something like this will work?

    JqJE.Jq(".class") ~> JqJE.JqHtml(Text(""))
    

    this basically constructs the same js code that @DrHossein wrote. Also, if you want, you can just use JsCmds.Run("") and inline everything you need as raw text.