Reading and setting DIV tag attributes

Posted on 2003-02-27
Medium Priority
Last Modified: 2013-11-19
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?

Question by:hollywood_noel
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

Accepted Solution

bhagyesht earned 200 total points
ID: 8040090
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
function myfunction()
     if  (document.getElementsByName("listingDIV")[0].text=="hello")

now call the function on the event u like

Expert Comment

ID: 9447452
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 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

771 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