Error .getAttribute is not a function

S

Steve

I am using Firefox and he following works fine in a .js file:

var target = document.getElementById("myheader").innerHTML;

But when I try
var targetId = target.getAttribute("id"); or
var targetId = target.getAttribute("id").innerHTML;

I get this error in Firebug "target.getAttribute is not a function"

I would be grateful for any assistance.
 
D

David Mark

I am using Firefox and he following works fine in a .js file:

var target = document.getElementById("myheader").innerHTML;

Leave off the ".innerHTML."
But when I try
var targetId = target.getAttribute("id"); or

Strings don't have a getAttribute method. This would fail in any
browser.
 
G

Gregor Kofler

Steve meinte:
I am using Firefox and he following works fine in a .js file:

var target = document.getElementById("myheader").innerHTML;

Returns a string.
But when I try
var targetId = target.getAttribute("id"); or
var targetId = target.getAttribute("id").innerHTML;

I get this error in Firebug "target.getAttribute is not a function"

Strings don't have a getAttribute() method.

Leave out the "innerHTML".

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top