Uncaught TypeError: Object #<an HTMLElement> has no method 'replace'

386 views
Skip to first unread message

Etherovamon

unread,
Jan 31, 2011, 4:55:10 PM1/31/11
to Chromium-extensions
First of all I would like to give you all my congrats for the great
work you are doing here.
I am building an extension, taking a value from a page and reusing
this value for a calculation. Then I inject the value in a div of the
page so I can see it.
The problem I came up with is this

"Uncaught TypeError: Object #<an HTMLElement> has no method 'replace'"

I have a string like "1,000"
I want to take out the "," and I use in the contentscript this code

var something;
something = document.getElementById('else');
something = something.replace(",","");

document.getElementById('whatever').appendChild(something);

PhistucK

unread,
Feb 2, 2011, 7:27:17 AM2/2/11
to Etherovamon, Chromium-extensions
You have a basic JavaScript DOM API error here.
This is not a JavaScript learning group. Please, next time, search for answers through a general search engine (if it also does not work within a regular web page\JavaScript, then it must be unrelated to extensions).

You are trying to call the "replace" method of a DOM element. Only strings (or special\user defined objects) have that "replace" method.
This is the right code -
var something = document.getElementById('else');
something.textContent = something.textContent.replace(",", "");

(No need to append it, it will change the element with this code already.)

PhistucK




--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Reply all
Reply to author
Forward
0 new messages