Re: [greasemonkey-users] Changing HTML code (NOT CSS) possible? Addressing NESTED,INNER

Sat, 02 Feb 2013 16:27:19 -0800

Am 02.02.2013 10:04, schrieb Ben:
Assume I have a HTML code similar to:
<html>
<table width="770" ...>
....
<table width="448" ...>
...
<table width="430" ...>
...
</table>
...
</table>
...
</table>
...
</html>
As you can see there are 3 nested table definitions. 1.) How can I change ALL <table width=...> definitions to <table width="98%" ...> All individual remaining <table> attributes and their values hould be kept
untouched.
2.) How can change the WIDTH attribute value of the second level <table>
definition ONLY to
<table width="90%" ...>
All individual remaining <table> attributes and their values hould be kept
untouched.
Ben


So to put it in a nutshell, you want all tables be changed to 98% width, and the second level to 90%?

Well, it'd indeed be the easiest with CSS, and I don't see a reason why you'd not want it, because that's 100% exactly what it is intended for:

table {
    width: 98%; /* All levels */
}
table table {
    width: 90%;/* All levels > 1 */
}
table table table {
    width: 98%; /* All levels > 2 */
}




But well, here you go... Solution for 1.):

var tables = document.getElementsByTagName("table");
for (var i = 0; i < tables.length; ++i) {
    var table = tables[i];
    table.setAttribute("width", "98%");
}

Solution for 2.) is maybe not so easy, because all methods I know don't care about the element's level, so you'd have to find out which level your table-node has on your own. How dynamical is your target page, is the second level table's tag always the second <table>-tag on the page or something like that?

Chris

--
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to