javascript - How to get an element that does not have an ID and exists multiple times in plain JS -
the following html have work with.
there no chance can change html or how constructed.
plain js requirement, no jquery solutions please.
the solution should variable containing table i'm looking for.
in direction: var tablecontent = getelementsomehow()
the table i'm referring starting @ line 87 , looks this: <table border=0 class='notifications'>
another information might helpful is, table referred to, forth table in whole html.
html:
<html> <head> <link rel="shortcut icon" href="/nagios3/images/favicon.ico" type="image/ico"> <title> alert notifications </title> <link rel='stylesheet' type='text/css' href='/nagios3/stylesheets/common.css'> <link rel='stylesheet' type='text/css' href='/nagios3/stylesheets/notifications.css'> </head> <body class='notifications'> <!-- produced nagios (http://www.nagios.org). copyright (c) 1999-2007 ethan galstad. --> <table border=0 width=100%> <tr> <td align=left valign=top width=33%> <table class='infobox' border=1 cellspacing=0 cellpadding=0> <tr><td class='infobox'> <div class='infoboxtitle'>contact notifications</div> last updated: wed jul 8 12:05:50 cest 2015<br> nagios® core™ 3.5.1 - <a href='http://www.nagios.org' target='_new' class='homepageurl'>www.nagios.org</a><br> logged in <i>kavan</i><br> </td></tr> </table> </td> <td align=center valign=top width=33%> <div align=center class='datatitle'> contacts</div> <br> <table border=0 cellspacing=0 cellpadding=0 class='navbox'> <tr> <td align=center valign=center class='navboxitem'> latest archive<br><a href='notifications.cgi?contact=all&type=0&archive=1'><img src='/nagios3/images/left.gif' border=0 alt='latest archive' title='latest archive'></a></td> <td width=15></td> <td align=center class='navboxdate'> <div class='navboxtitle'>log file navigation</div> wed jul 8 00:00:00 cest 2015<br>to<br>present..</td> <td width=15></td> <td><img src='/nagios3/images/empty.gif' border=0 width=75 height=1></td> </tr> </table> <br><div class='navboxfile'>file: /var/log/nagios3/nagios.log</div> </td> <td align=right valign=top width=33%> <form method='get' action='notifications.cgi'> <input type='hidden' name='contact' value='all'> <input type='hidden' name='archive' value='0'> <table border=0 class='optbox'> <tr> <td align=left colspan=2 class='optboxitem'>notification detail level contacts:</td></tr> <tr> <td align=left colspan=2 class='optboxitem'><select name='type'> <option value=0 selected>all notifications <option value=1 >all service notifications <option value=2 >all host notifications <option value=8192 >service custom <option value=512 >service acknowledgements <option value=4 >service warning <option value=8 >service unknown <option value=16 >service critical <option value=32 >service recovery <option value=2048 >service flapping <option value=16384 >host custom <option value=1024 >host acknowledgements <option value=64 >host down <option value=128 >host unreachable <option value=256 >host recovery <option value=4096 >host flapping </select></td> </tr> <tr> <td align=left class='optboxitem'>older entries first:</td> <td></td> </tr> <tr> <td align=left valign=bottom class='optboxitem'><input type='checkbox' name='oldestfirst' ></td><td align=right class='optboxitem'><input type='submit' value='update'></td> </tr> <tr><td></td><td align=right valign=bottom> <a href='/nagios3/contexthelp/f1.html' target='cshw' onclick='javascript:window.open("/nagios3/contexthelp/f1.html","cshw","width=550,height=600,toolbar=0,location=0,status=0,resizable=1,scrollbars=1");return true'><img src='/nagios3/images/contexthelp1.gif' border=0 alt='display context-sensitive screen' title='display context-sensitive screen'></a> </td></tr> </table> </form> </td> </tr> </table> <p> <div align='center'> <table border=0 class='notifications'> <tr> <th class='notifications'>host</th> <th class='notifications'>service</th> <th class='notifications'>type</th> <th class='notifications'>time</th> <th class='notifications'>contact</th> <th class='notifications'>notification command</th> <th class='notifications'>information</th> </tr> <tr class='notificationseven'> <td class='notificationseven'><a href='extinfo.cgi?type=1&host=vladimir'>vladimir</a></td> <td class='notificationseven'><a href='extinfo.cgi?type=2&host=vladimir&service=vmware%3a+status'>vmware: status</a></td> <td class='notificationscritical'>critical</td> <td class='notificationseven'>2015-07-08 12:02:20</td> <td class='notificationseven'><a href='config.cgi?type=contacts#it'>it</a></td> <td class='notificationseven'><a href='config.cgi?type=commands#notify-by-email'>notify-by-email</a></td> <td class='notificationseven'>critical: execution time long!</td> </tr> <tr class='notificationsodd'> <td class='notificationsodd'><a href='extinfo.cgi?type=1&host=hp2520-edv'>hp2520-edv</a></td> <td class='notificationsodd'>n/a</td> <td class='notificationshostdown'>host down</td> <td class='notificationsodd'>2015-07-08 11:48:20</td> <td class='notificationsodd'><a href='config.cgi?type=contacts#it'>it</a></td> <td class='notificationsodd'><a href='config.cgi?type=commands#host-notify-by-email'>host-notify-by-email</a></td> <td class='notificationsodd'>critical - host unreachable (192.168.1.206)</td> </tr> </table> </div> </p> <!-- produced nagios (http://www.nagios.org). copyright (c) 1999-2007 ethan galstad. --> </body> </html>
another information might helpful is, table referred to, forth table in whole html.
if it's 4th table in document. try
var tablecontent = document.getelementsbytagname('table')[3];
Comments
Post a Comment