Changing colspan="16" value to "17"

Subscribe to Changing colspan="16" value to "17" 4 posts, 3 voices

 
William Scriptwright

Any suggestions on how to change this:

colspan="16"

to this?

colspan="17"

I tried using xpath and innerHTML but the table isn't turning out correctly.

 
Arvid Scriptwright

Well, you'll have to give us more details. On what page? How does your code look like right now? It should be as easy as setAttribute('colspan', '17') if you have selected the correct nodes with XPath.

 
William Scriptwright

Thanks for your help. I found another way to do it based on your reply. On this page (http://fantasygames.sportingnews.com/baseball/s...) I'm trying to add another column. This code seems to be working:

var blahs = document.getElementsByTagName('TD');
for (var i = 0; i < blahs.length; i++) {
var blah = blahs[i];
if (blah.getAttribute('COLSPAN')) {
var match = blah.getAttribute('COLSPAN').match('16');
if (match)
blah.setAttribute('COLSPAN', '17');
}
}

 
Descriptor Scriptwright

Here's a shortcut using Xpath...

var blahs = document.evaluate("//td[@colspan='16']", document, null,
			XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < blahs.snapshotLength; i++) {
	var blah = blahs.snapshotItem(i);
	blah.setAttribute('colspan', '17');
}

The thing is I don't know if attribute case is an issue, they should really all be lower case but often they're mixed up and ones like COLSPAN are often upper case. In Xpath I think @attribute is not case sensitive but the value is, which isn't an issue here since it's a number.

If for some reason setAttribute don't work try
blah.colspan = '17';