[英]how can I get a value inside Tr using javascript
How can I get "Test2" using JavaScript? 如何使用JavaScript获得“ Test2”?
Here is my HTML: 这是我的HTML:
<table>
<th> </th>
<tr id = "123">
<td>
<UL>
<Li> Test1 </Li>
<Li> <a class ="SomeClass" >Test2 <a/> </Li>
</UL>
</td>
</tr>
</table>
You can use document.getElementsByClassName
: 您可以使用
document.getElementsByClassName
:
var a = document.getElementsByClassName('SomeClass');
var value = a[0].innerHtml;
If you are already using jQuery you can simply use 如果您已经在使用jQuery,则只需使用
$('.SomeClass').text();
Hope this helps! 希望这可以帮助!
Try the following JavaScript code to do it. 请尝试以下JavaScript代码来实现。
var example = document.getElementById('test2').innerHTML; alert(example);
<table> <th></th> <tr id="123"> <td> <UL> <Li>Test1</Li> <Li> <a class="SomeClass" id="test2">Test2 <a/> </Li> </UL> </td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.