如何在不使用ID的情况下查找元素 [英] How to find element without use ID

查看:100
本文介绍了如何在不使用ID的情况下查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数组中有DOM元素

I have DOM element in array

this.object = 
     <div>
     <span class="color">"color1</span> 
     <span class="text">text1</span>
     </div>

     <div>
     <span class="color">"color2</span> 
     <span class="text">text2</span>
     </div>

     <div>
     <span class="color">"color3</span> 
     <span class="text">text3/span>
     </div>

     <div>
     <span class="color">"color4</span> 
     <span class="text">text4</span>
     </div>

这个DOM存在于DOM数组中(this.object)

this DOM is exist in array of DOM ( this.object )

我如何仅更新数组中的第一个跨度或仅更新第二个跨度,我不能使用我的程序技术问题中的ID。

How I update only the first span or only the second span in the array, I can't use ID from technical issue of my program.

我试图使用
this.element.children [i] 但后来我不知道如何找到第一个或第二个跨度

I tried to use this.element.children[i] but then I didn't know how to find the first or second span

推荐答案

使用jQuery避免任何跨浏览器问题。假设您有div,请使用 div.find('span:eq(1)');

Use jQuery to avoid any cross browser issues. Assuming you have the div, use div.find('span:eq(1)');

< a href =http://jsfiddle.net/Ybu6n/ =nofollow>工作示例。

多个项目的工作示例

另一个示例显示正在更新的文本。

Another example showing the text being updated.

这篇关于如何在不使用ID的情况下查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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