javascript - Need help finding a "tr" tag with a nested "th" tag -
i developing code snippet use tasvideos tas submission finder. snippet add "td" tag beginning of each list entry, people fast readers (and people aren't, since i'm using 3 letter codes) can find tasvideos.org approved tas's , @ them, or other tas want. have 2 modes (system , status). working on status portion , had error. here code.
wikitable = document.getelementsbyclassname("wikitable")[0]; wikitabletr = wikitable.getelementsbytagname("tr"); var tr; quickscrubheader = document.createelement("th") qshtext = document.createtextnode("quickscrub tas videos") quickscrubheader.appendchild(qshtext) wikitabletr.getelementsbytagname("th")[0].insertbefore(quickscrubheader) (var tr in wikitabletr){ delete addend, addendtext; td = tr.getelementsbytagname("td"); addend = document.createelement("td") if(td[3].innerhtml == "published");{ addendtext = document.createtextnode("pub") addend.appendchild(addendtext) tr.insertbefore(addend) } }
the sloppy block of code this:
quickscrubheader = document.createelement("th") qshtext = document.createtextnode("quickscrub tas videos") quickscrubheader.appendchild(qshtext) wikitabletr.getelementsbytagname("th")[0].insertbefore(quickscrubheader)
i know how make last line of sloppy code work finds "tr" tag "th" tags inside, , puts quickscrubheader
element before other elements, how for/in loop have looks value in td[3]
, inserts special "td" tag @ beginning of list.
you can use queryselectorall , parentnode:
var th_list = document.queryselectorall('.wikitable > tr > th'); th_list[0].parentnode.insertbefore(quickscrubheader,th_list[0]);
Comments
Post a Comment