i'm trying to get the contents of the span fields "sector" & "coords" from this :

header crap snipped out.

<body style="background-image:url('http://www.pardus-lcn.org/assets/pardus/bgoutspace1.gif')">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:5px;">
<td valign="top">
<table width="210" border="0" cellspacing="0" cellpadding="0" id="status"><tr><td><img src="http://www.pardus-lcn.org/assets/pardus/status.png" width="210" height="34" alt=""></td></tr><tr><td style="background-image:url('http://www.pardus-lcn.org/assets/pardus/panel.png');background-repeat:repeat-y;text-align:left;"><div style="margin:0 18px;"><table cellspacing='2' cellpadding='1' border='0' width='95%'>

<tr valign='middle'>
<td align='center'><b><span id='sector'>Fornacis</span></b> </td>
<td align='left'><span id='coords'>[1,23]</span> </td>


i've tried this and a few different combinations

var tm = document.getElementById('sector').innerText  ;
			alert("tm:" + tm );

i've tried it w/out the .innertext, and with .innerhtml, and nothing.

i've not been able to pull that information out

what am i doing wrong here?

9 Years
Discussion Span
Last Post by essential

How do you trigger that effect?
Here's another way to call element's in your page.

<title>test page</title>
<script type="text/javascript">
var tm;
window.onload = function() {
try {
alert( "tm: " + document.getElementsByTagName("span")["sector"].innerText );
} catch(e) {
tm = ((document.getElementById ) ? document.getElementById("sector").innerText : document.all.sector.innerText );
alert("tm: " + tm );
// -->
<span id="sector">sample text</span>
<!-- page content -->

Hope it helps...


its being called through a firefox extention.

the solution you posted does not work :(

i changed it some to try to catch the actuall error

	alert( "tm: " + document.getElementsByTagName("span")["sector"].innerText );
} catch(err) 
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.description + "\n\n";
  txt+="Click OK to continue.\n\n";


There was an error on this page.

Error description: undefined

Click OK to continue.

does it matter that the span i want is nested inside a table(look at orig code)


A simple function that generates error... I'm so confused how things really work in your browser, ff widely understand the getElementsByTagName method and yet it fail's to execute the script.
Try the catch(err){ (( err.description ) ? alert( err.description ) : alert( err.message )); } and see which part generates the error.


No it doesn't matter, as long as you provide valid id's that exist. And It has to work with getElementById method in ff, or the document.all for IE6-version.


No it doesn't matter, as long as you provide valid id's that exist. And It has to work with getElementById method in ff, or the document.all for IE6-version.

well the ID exists, i can see it in the show source code screen, yet FF cannot seem to find it.


Sorry, but that's not the right way. It should be like this:

var tm = documen.getElementsByTagName("span")["sector"].innerText;

and you can also try this format:

var tm = documen.getElementsByTagName("span").item("sector").innerText;

just use one.


both return undefined(and yes i fixed the typo of documen to document)


Then you have this last method to get your element:

var tm = (( document.getElementById ) ? document.getElementById("sector").innerText : document.all.sector.innerText );

the getElementById method should fixed this, even w/o using the document.all . And try to check if you have broken tag's in your document.
If its still doesn't work then, im afraid i cannot offer another solution asside from those last 3 posted code. Good day to you...


You can use, this toolkit to get all the elements you need in your page. It's currently under development, but it wil give the easy work of skipping the whole delclaration of document.getElementById("yourElem") you can just call your elements using get("sector").innerText and this is a cross-browser script. Simply include it via .js.

/* UNDER Development */

var get, getID;
getID = Boolean( document.getElementById );
get = Object.prototype.get = function( ID ) {
   if ( ID ) { 
   verifyID = document.getElementsByTagName("*");
   cutID = ID.split( /\d+/g )[0];
      for ( var x = 0; x < verifyID.length; x++ ) {
      check = verifyID[ x ].id.indexOf( ID ); 
         if ( check >= 0 ) { break; 
      if (( check !== -1 ) && ( document.getElementById( ID )) || ( eval( "document.all." + ID + ";" ))) { 
      return (( getID ) ? document.getElementById( ID ) : eval("document.all." + ID + ";"));
      else if (( check !== -1 ) && ( document.getElementsByTagName( cutID ))) { 
      return document.getElementsByTagName( cutID )[ ((( document.getElementsByTagName( cutID ).length ) + x ) - verifyID.length ) ];
      else { 
      return alert("\nThere's is no such (" + ID + ") element on this document!\nPlease verify your element id.");

i think i just realized the problem,

the document i'm running the JS on is inside of a frame, do i have to do something funky to have it run in the particular frame?


thats not something that i can do, its a firefox extention, not something directly on the page.


Provide your frame's with ids, then get the element's on that frame by doing this:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.