Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.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
在jquery中查找html元素_Html_Jquery Selectors - Fatal编程技术网

在jquery中查找html元素

在jquery中查找html元素,html,jquery-selectors,Html,Jquery Selectors,我应该找到一个类并应用逻辑。 我的代码结构如下 <div class="class"> <form> <ul> <li>xxx</li><li>xxx</li> </ul> <ul> <li>xxx</li><li>xxx</li> </ul> <u

我应该找到一个类并应用逻辑。 我的代码结构如下

<div class="class">

  <form>

    <ul>
      <li>xxx</li><li>xxx</li>
    </ul>

    <ul>
      <li>xxx</li><li>xxx</li>
    </ul>

    <ul class="ul_class">

      <li>
        <input ....><a ...><span ..></span>
        <a href="#" title="View History" class="hstry">
        <span class="hide">&nbsp;</span></a>
      </li>

      <li>xxx</li>

     </ul>

   </form>

  • xxx
  • xxx
  • xxx
  • xxx
  • xxx

如何在名为
ul_class
ul
类中查找类
hstry
,只需使用普通CSS选择器查找嵌套类,如下所示:

$( 'ul.ul_class .hstry' )

注意两个类之间的空白。如果没有它,它将匹配具有两个类的元素,而不是一个class
hstry
的元素,该元素低于class
    的某个
    元素

    var hstry=$('body').find('.hstry').html()

    然后,您可以任意使用此变量进行操作。

    使用jquery:
    $(“ul.ul_类”).find(“.hstr”)

    比如说,我有3个ul,属于同一类别,如何定位我的第一个ul并访问其.hstryclass@Abdul在这种情况下,只需将
    .first()
    附加到第一个匹配元素。看见
    $('ul.ul_class .hstry').html(); //for html content
    $('ul.ul_class .hstry').text(); //for text data