hey guys, wonder what i'm doing wrong?
javascript:document.getElementsByTagName('textarea').innerHTML='inserted';
i want to create a bookmarklet to insert simple text to a textarea on a given webpage.
regards matt
hey guys, wonder what i'm doing wrong?
javascript:document.getElementsByTagName('textarea').innerHTML='inserted';
i want to create a bookmarklet to insert simple text to a textarea on a given webpage.
regards matt
Use the value
:
javascript:document.getElementsByTagName('textarea').value = 'inserted';
In jQuery you have to use if this way:
for single element -> $('#element_id').html('your html here')
for all text areas -> $('textarea').val('your html here')
I have to confess that I`m not sure why it works this way but it works. And use rameworks, they will save you time and nerves.
Use the value
property rather than innerHTML
and make sure your code evaluates to undefined
, which you can do by wrapping it in a function with no return
statement. If you don't do this, the contents of the page will be replaced with whatever your code evaluates to (in this case, the string 'inserted').
javascript:(function() {document.getElementsByTagName('textarea').value = 'inserted';})();