Problem solve Get help with specific problems with your technologies, process and projects.

How do I get at the value of the "level" attribute?

I am using JavaScript to display search results from an XML file to an HTML file (using .innerHTML). I have no problem accessing any element I want, but I cannot seem to get at the attributes (e.g., <objective level="1"> content here</objective>). How do I get at the value of the "level" attribute?
innerHTML will return a string. This string can be used to create a DOM. From there, the methods to access elements and attributes are per the DOM specifications. In particular, if you have an Element object you can use the getAttribute() method to retrieve an attribute value.

Dig Deeper on Topics Archive

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.