Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-01-2011, 10:45 PM   PM User | #1
DaveyJake
New to the CF scene

 
Join Date: Oct 2010
Location: Orange County, CA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
DaveyJake is an unknown quantity at this point
Beginner Question on Modifying Text w/ Greasemonkey

JavaScript has always haunted me as a language. I know HTML and CSS but JS always ruins me!

I'm trying to write a very simple, very basic script just to see if I can get the hang of it. I'm trying to tweak the appearance of my Gmail address inside my inbox.

Instead having my address being displayed as firstlast@gmail.com, I would rather have it as first.last@gmail.com. Here's is my code:

Code:
(function () {
	
	var newEmail = "first.last@gmail.com";
	var nameTag = document.getElementsByTagName('span').getElementById('gbi4t')[0];
	nameTag.setAttribute(innerHTML, newEmail);

}) ();
I just can't seem to get it to work. What am I doing wrong?
DaveyJake is offline   Reply With Quote
Old 09-02-2011, 02:59 PM   PM User | #2
LRM
New Coder

 
Join Date: Sep 2011
Posts: 11
Thanks: 0
Thanked 2 Times in 2 Posts
LRM is an unknown quantity at this point
First, each ID name should only ever be defined/used once on a page.

Next:
getElementsByTagName() returns an array of pointers, accessible numerically through an array reference [#] tacked on at the end like this: getElementsByTagName()[0].

getElementById() returns a single pointer (which is one reason why an ID name should only be used once on a page - your script won't know which one you mean).

So far, it appears your script is backwards and should probably be:
var nameTag = document.getElementById('gbi4t').getElementsByTagName('span')[0];

Since I can't imagine gMail using improper coding, if the span containing the email address you want to change has the id gbi4t this is probably all you need.
var nameTag = document.getElementById('gbi4t');

If it is the first span inside of a container that has the id gbi4t its as I pointed out above:
var nameTag = document.getElementById('gbi4t').getElementsByTagName('span')[0];


I'm just guessing here since I don't know exactly what you are trying to reference.
LRM is offline   Reply With Quote
Reply

Bookmarks

Tags
beginner, gmail, greasemonkey, manipulation, text

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:24 AM.


Advertisement
Log in to turn off these ads.