Javascript jQuery CSS选择器与“组合”;这";
我想知道这样的事情是否可能。我们得到了HTML结构Javascript jQuery CSS选择器与“组合”;这";,javascript,jquery,html,jquery-selectors,Javascript,Jquery,Html,Jquery Selectors,我想知道这样的事情是否可能。我们得到了HTML结构 <a href='#' class='anyLink'> <!-- here goes some content--> <div class='childElement'><!-- here goes some content--></div> </a> 我希望选择已单击的锚点的子元素,或者希望获取子元素的值。我也没有任何children元素的ID,我正
<a href='#' class='anyLink'>
<!-- here goes some content-->
<div class='childElement'><!-- here goes some content--></div>
</a>
我希望选择已单击的锚点的子元素,或者希望获取子元素的值。我也没有任何children元素的ID,我正试图通过CSS选择器选择内容,如td:nth child(4)
。
有人能告诉我这是否可行吗?试试看
$('a').on("click",function(e){
$(this).children("div").eq(0).html();
});
试一试
您正在寻找一个名为的函数 但您也可以尝试以下方法:
$('a').on('click', function( e ) {
$('div', this).val(); // Each div child of this element
$(this).children('div'); // Each div child of this element
});
您正在寻找一个名为的函数 但您也可以尝试以下方法:
$('a').on('click', function( e ) {
$('div', this).val(); // Each div child of this element
$(this).children('div'); // Each div child of this element
});
我喜欢并使用第二个建议。谢谢老兄,你帮了我很多@艾维普:如果这有帮助,一定要接受这个答案:-)我喜欢并使用第二个建议。谢谢老兄,你帮了我很多@艾维普:如果这有帮助,一定要接受这个答案:-)对不起,但我知道。孩子们。我必须通过css选择器访问您可以使用选择器作为子对象的第一个参数。对不起,我知道。孩子们。我必须通过css选择器访问您可以使用选择器作为子对象的第一个参数。
$('a').on('click', function( e ) {
$('div', this).val(); // Each div child of this element
$(this).children('div'); // Each div child of this element
});