如何使用jQuery直接跨度 [英] How to aceess span directly using jQuery

查看:156
本文介绍了如何使用jQuery直接跨度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在下面的html结构中访问此[span class ="myclass"].

I want to know how to get access of this [span class="myclass"] in below html structure..

        <ul>
    <li class="first">
      <span class="myclass"></span>
      <div class="xx">

        <span></span>
        ........
          </div>
   <li >
      <span class="myclass"></span>
      <div class="xx">

        <span></span>
         ........
      </div>
     </ul>

在这里,我需要在[span class ="myclass"]中编写一个函数,但是我无法使用$(.myclass")来完成它.[我有几个问题]我只想直接访问span本身.要做到这一点..?

Here I need to write one function in [span class="myclass"], but i cant do it using $(".myclass") [I have few issues] I just want to directly access the span itself.How to do this..?

编辑:凤凰城的sln正常工作..但是(据我所知)结构是

EDIT:the sln by phoenix is working fine..but lets say(just for my knowledge) the structure is

  <li >
      <span class="myclass"></span>
      <div class="xx">
        <li>
        <span></span>
       </li>
         ........
      </div>
   </ul>

所以为什么第二个li(在div下)的范围没有得到引用,是bcoz它们不在同一级别..如果我需要访问它们,我需要做一些类似的事情

so why the span inside 2 nd li(which is under div) is not getting the ref, is it bcoz they are not in the same level..if I need to access them do I need to do some thing like

enter code here

$("li").next(.xx").find(li span:first-child)..或者还有其他东西吗? 谢谢.

$("li").next(".xx").find(li span:first-child )..or something else is there? Thanks.

推荐答案

如果span是第一个孩子,则可以使用

If span is the first child then you can use

第一个孩子

选择器

$("li span:first-child");

这篇关于如何使用jQuery直接跨度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆