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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:17:39+00:00 2026-05-26T00:17:39+00:00

I am trying to change the class of one or more elements within a

  • 0

I am trying to change the class of one or more elements within a template when a button is clicked. The samples I have ssen all usually find one item with .tmplItem, and I can’t quite figure out how to achieve what I’m trying to do. This is more or less a proof of concept.

i have a structure like below.

var messages = [
{ Body: "Testing 1", Read: "0" },
{ Body: "Testing 2", Read: "1" },
{ Body: "Testing 3", Read: "0" },
{ Body: "Testing 4", Read: "1" }
];

my template is:

    <script id="messageTemplate" type="text/html">
        {{if Read == "1"}}
        <tr class="hdnMessage">
            <td class="hdnMessage" >
<input type="checkbox" id="cbHasReadMessage" checked="checked">
</td>
        {{else}}
        <tr class="showMessage">
            <td><input type="checkbox" id="cbHasReadMessage"></td>
        {{/if}}        
        <td>${Body}</td>
        </tr>
</script>

css is:

<style type="text/css">
.hdnMessage 
{
    display:none;
}
.showMessage
{
    display:block;
}
</style>

I have a button outside of the template

<input type="button" value="Show Read Messages" id="btnShowHideReadMessages" />

which I added a click event for:

$("#btnShowHideReadMessages").click(function() {    
if (showingReadMessages) {
      showingReadMessages = false;
      $(this).val("Show Read Messages");
//try to find checked checkboxes and set the class of the tr which is its parent
}    
else {
      showingReadMessages = true;
      ///Try finding all the current hidden TRs
      var hdnMessages = $("tr.hdnMessage").tmplItem();
      var hdnMsg = hdnMessages.data;
      var hdnElement = hdnMessages.nodes;
      $(hdnElement).replaceWith($('.showMessage'));
      }    
});

The last script segment is incomplete as I couldnt figure out how to get this to work. Any help would be 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. Editorial Team
    Editorial Team
    2026-05-26T00:17:39+00:00Added an answer on May 26, 2026 at 12:17 am

    Remove class="showMessage" from the template altogether then change the bottom section of code to something like this:

    $("#btnShowHideReadMessages").click(function() {  
         $("tr.hdnMessage").toggleClass('hdnMessage');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to change the class of a element with Javascript using the
I am trying to change the property type in interface implementation class using explicit
I am trying to access/change the properties of a class' Parent through Reflection. If
I´m trying to change a spring jsp example to use freemarker. I changed all
I'm trying to change a Button's Click property/event when a DataTrigger is triggered but
Lets say we have a main class with 5 buttons, where when each clicked
suppose I have a file alpha.h: class Alpha { public: template<typename T> void foo();
I'm learning Python and have been trying to understand more about the details of
I am trying to access and change a array from a different class file.
I am trying to replace div elements with button elements to improve accessibility, but

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.