javascript - How can I select a nested element without an id or class? -


for example, suppose had following html:

<div>   <table>     <tr>       <td>x</td>       <td></td>     </tr>   </table> </div>  <div></div> 

and wished fin value within td element x in it. know use

var foo = document.getelementsbytagname("td")[0].innerhtml; 

in order select specific td element, , not 1 of others. however, given know path element, how can javascript used in way select particular value?

you should first tr

var tr = document.getelementsbytagname("tr")[0];  var foo = tr.getelementsbytagname("td")[0].innerhtml;  console.log(foo);
<div>  <table>  <tr>  <td>x</td>  <td></td>  </tr>  </table>  </div>    <div></div>


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -