Solved

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

Posted on 2003-12-08
4
1,396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

630 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