Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Reading and setting DIV tag attributes

Using Javascript, I'm trying to do the following -

1.  Read the ID and name attribute of a DIV tag
2.  Depending on the value of the DIV ID attribute, set the STYLE:visibility tag to either 'hidden' or 'visible'.

Here's the DIV tag I'm working with -

<DIV ID=23453 STYLE=visibility:visible; name=listingDIV>

What's the best way to go about accessing the values?

Noel
0
hollywood_noel
Asked:
hollywood_noel
1 Solution
 
bhagyeshtCommented:
first of all it wont work on IE ie requires id and name to be the same ie document.getElementsbyName still searches for id
so first of all make id and name have the same value
like below.
<DIV ID=listingDIV STYLE=visibility:visible; name=listingDIV>

now your value u need can be assigned in a text property like
<DIV ID=listingDIV STYLE=visibility:visible; name=listingDIV text=23453 >
 and your script could be like
<script>
function myfunction()
{
     if  (document.getElementsByName("listingDIV")[0].text=="hello")
     {
          document.getElementsByName("listingDIV")[0].style.visibility="hidden";
     }
     else
     {
          document.getElementsByName("listingDIV")[0].style.visibility="visible";
     }
}
</script>

now call the function on the event u like
0
 
CleanupPingCommented:
hollywood_noel:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now