Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery CSS选择器与“组合”;这";_Javascript_Jquery_Html_Jquery Selectors - Fatal编程技术网

Javascript jQuery CSS选择器与“组合”;这";

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,我正

我想知道这样的事情是否可能。我们得到了HTML结构

<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
});