wtmh
08-20-2010, 07:21 PM
I'm brand new to JavaScript, and I come from a purely logical scripting background so forgive me if this is the most poorly formed code/bad technique that you've recently seen.
I've played the google games for days and I surrender. I usually find a way to fight through it and figure it out, but I'm going to have to cede this one.
I'm simply trying to put a new tab next to a tab that is already present on a page (classed: mirrortab_first)
I'm trying to use XPath to select the element and then place newTab before it.
Seemed simple enough to start. But as the code sits, the tab always winds up at the bottom of the page.
Any thoughts?
Kind regards.
var newTab = document.createElement("div");
newTab.setAttribute('id','newTab');
newTab.innerHTML =
'<table cellpadding="0" cellspacing="0" border="0"><tbody><tr>' +
'<td class="mirrortab_first"> </td>' +
'<td class="mirrortab_back">' +
'<a style="cursor:pointer;">Hide Classifieds</a>' +
'</td>' +
'<td class="mirrortab_last"> </td>' +
'</tr></tbody></table></div>';
var tabLocation = document.evaluate('//td[contains(@class, "mirrortab_first")][1]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for (i=0; i<tabLocation.snapshotLength; i++)
{
tL = tabLocation.snapshotItem(i).parentNode;
}
document.body.insertBefore(newTab, document.tL);
I've played the google games for days and I surrender. I usually find a way to fight through it and figure it out, but I'm going to have to cede this one.
I'm simply trying to put a new tab next to a tab that is already present on a page (classed: mirrortab_first)
I'm trying to use XPath to select the element and then place newTab before it.
Seemed simple enough to start. But as the code sits, the tab always winds up at the bottom of the page.
Any thoughts?
Kind regards.
var newTab = document.createElement("div");
newTab.setAttribute('id','newTab');
newTab.innerHTML =
'<table cellpadding="0" cellspacing="0" border="0"><tbody><tr>' +
'<td class="mirrortab_first"> </td>' +
'<td class="mirrortab_back">' +
'<a style="cursor:pointer;">Hide Classifieds</a>' +
'</td>' +
'<td class="mirrortab_last"> </td>' +
'</tr></tbody></table></div>';
var tabLocation = document.evaluate('//td[contains(@class, "mirrortab_first")][1]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);
for (i=0; i<tabLocation.snapshotLength; i++)
{
tL = tabLocation.snapshotItem(i).parentNode;
}
document.body.insertBefore(newTab, document.tL);