Skip to content
Advertisement

How to get the id & title of a DIV element, using pure JavaScript

I have an element:

JavaScript

I am trying to get both the id and the title, formatted as such:

JavaScript

I’m also trying to use pure Javascript. This is what I have been playing with so far:

JavaScript

Does anyone know how to proceed?

Advertisement

Answer

Mistakes that you have made

  1. <= should be changed to <
  2. Didn’t close the tag properly

To get the id you can use element.id

To get the title you can use element.getAttribute('title')

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement