Solved

Changing class name of "tr" element dyncamically using IHTMLElement->put_className

Posted on 2003-12-08
4
1,353 Views
Last Modified: 2013-11-20
I want to be able to dynmically hide/unhide rows in a table. In my CDHtmlDialog class I call a function to changing the class of specific "tr" element to hidden. It appears to do that but the elements within the "tr" are still visable (buttons, text input, etc), although their text is removed. If I specify in the html file that the "tr" element is hidden innitially then everything is hidden correctly so there's nothing wrong with my html method. But I've no idea what else I can try. The html is listed below followed by


<tr id="line1">
      <td>Image 1</td>
      <td><button id="Browse">Browse 1</button></td>
      <td><input name="image1filename" type="text" readonly="true"></td>
</tr>


if (sTempTagName == _T("tr"))
{
      VARIANT varTagID;
      VariantInit(&varTagID);
      if (SUCCEEDED(pElem->getAttribute(L"id",0,&varTagID))
            && (varTagID.vt != VT_NULL))
      {
            CString strID = (CString)varTagID.bstrVal;
            if (strID == "line2")
                  pElem->put_className(L"hidden");
      }
      VariantClear(&varTagID);
}
0
Comment
Question by:wjdashwood
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:luvjd
ID: 9902658
Can u give the code which hides the tr element ? (Directly in the HTML file)
0
 

Author Comment

by:wjdashwood
ID: 9903443
Forgot to complete my last sentence. Oops! Here's the code which uses IHTMLElement->put_className to change the "tr" element  to my hidden class which is defined in my CSS file as shown at the bottom. Thanks.

if (sTempTagName == _T("tr"))
{
     VARIANT varTagID;
     VariantInit(&varTagID);
     if (SUCCEEDED(pElem->getAttribute(L"id",0,&varTagID))
          && (varTagID.vt != VT_NULL))
     {
          CString strID = (CString)varTagID.bstrVal;
          if (strID == "line2")
               pElem->put_className(L"hidden");
     }
     VariantClear(&varTagID);
}

.hidden
{
      visibility:hidden;
}
0
 
LVL 1

Accepted Solution

by:
luvjd earned 500 total points
ID: 9903722
Hi..
It seems that we have to hide the definitions ( td).. without which it is not working...
I Could get the tag name also after setting it as hidden ..but for the input elements and buttons , we have  to hide them explicitly.. normal text td's are hidden if we hide the tr...
Check the following Code...

                                      MSHTML::IHTMLDocument2Ptr pDoc(GetHtmlDocument());      
                  MSHTML::IHTMLDocument3Ptr pDoc3 = pDoc;      
                  MSHTML::IHTMLElementCollectionPtr pCollection ,pCollection1;      
            
                  MSHTML::IHTMLElementPtr pEle,pEle2;
            
                  pCollection = pDoc3->getElementsByTagName(_T("tr"));
                        pCollection1 = pDoc3->getElementsByTagName(_T("td"));
                  if(pCollection)
                  {
                        pEle = pCollection->item(CComVariant(0),CComVariant(0));
                        pEle2 = pCollection1->item(CComVariant(0),CComVariant(0));
                        //pEle->put_className(L"hidden");
                        BSTR className[10];
                        //pEle->get_className(className);
                        //pEle->setAttribute(L"class",L"hidden",2);
                        pEle->put_className(L"hidden");
                        pEle2->put_className(L"hidden");
                        pEle->get_className(className);
                        

                  }

Luv..
Jd
0
 

Author Comment

by:wjdashwood
ID: 9903747
Oh well, if that's the only way to do it then I guess it's not too bad. I'm a freak for efficiency so I would have loved to be able to hide everything with just one line of code :)

Many thanks for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
has22 challenge 11 80
Examples of Web API, REST web services and SOA 7 184
Problem to echo 6 81
Swiper slider stops between pages 11 45
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now