JQuery - 使用脚本在表中获取div ID [英] JQuery - Get div ID inside table using script
问题描述
hi,
我有带ID的html表,我想知道使用jquery在第一行第一列内的div的id
I have html table with ID and I want to find out id of div inside first row first column using jquery
示例 -
Example -
< table id =" mytable" ; >
<table id="mytable" >
< tr>< td> < div id =" divtofind" > XYZ< / div>< / td>< / tr>
<tr ><td> <div id="divtofind" >XYZ</div></td></tr>
< tr>< td> < div> ABC< / div>< / td>< / tr>
<tr ><td> <div >ABC</div></td></tr>
< / table>
</table>
我知道桌子和桌子的ID我需要遍历到div才能得到相应div的id,即'divtofind'。
i know id of table & i need to traverse till div to get id of respective div i.e. 'divtofind'.
我是初学者在JQuery中。任何人都可以建议这样做吗?
I am beginner in JQuery. Can anybody suggest way to achive this?
谢谢
推荐答案
看看这个,是获取第一个元素的选择器:
Check out this, is a selector for get the first element:
<div>
<span>John,</span>
<span>Karl,</span>
<span>Brandon</span>
</div>
<div>
<span>Glen,</span>
<span>Tane,</span>
<span>Ralph</span>
</div>
<script>
(" div span:first-child")
.css(" text-decoration"," underline")
.hover(function(){
("div span:first-child") .css("text-decoration", "underline") .hover(function () {
(this).addClass(" sogreen");
},function(){
(this).addClass("sogreen"); }, function () {
这篇关于JQuery - 使用脚本在表中获取div ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!