所以,我有一个网站,我只有类来处理隔离我想编辑的元素。我需要找到一个在html中包含特定字符串的元素,并替换它的一个兄弟html。不管怎么说,这里是我得到的代码:找到包含字符串的元素并替换同级元素
if((".user.info").html().indexOf(vaUID[index]) >= 0) {
$("a.user.info").each(function (index2, obj) {
if($(this).html().indexOf(vaUID[index]) >= 0) {
$(this).siblings('.registered').html('<div class="registered"><a href=http://www.twitch.tv/'+users[index]+ '>currently streaming' + data.stream.game + '</a></div>');
}
});
}
这里的起始HTML:
<div class="user first">
<div class="element_avatar simple small "><a href="http://www.cnr-clan.com/profile/xxxxxx" data-minitooltip="username"><img src="http://assets-cloud.enjin.com/users/xxxxxx/avatar/small.xxxxxx.png"></a></div>
<div class="info">
<a href="http://www.cnr-clan.com/profile/xxxxxx" class="element_username tag-xxxxxx">username</a>
<span class="nameicons">
<!--Irrelevant Excess Code-->
</span>
<div class="registered">currently browsing</div>
</div>
<div class="clearing"><!-- --></div>
</div>
我想结束了什么:
<div class="user first">
<div class="element_avatar simple small "><a href="http://www.cnr-clan.com/profile/xxxxxx" data-minitooltip="username"><img src="http://assets-cloud.enjin.com/users/2219573/avatar/small.xxxxxx.png"></a></div>
<div class="info">
<a href="http://www.cnr-clan.com/profile/xxxxxx" class="element_username tag-xxxxxx">username</a>
<span class="nameicons">
<!--Irrelevant Excess Code-->
</span>
<div class="registered"><a href='http://www.twitch.tv/username'>currently streaming gamename</a></div>
</div>
<div class="clearing"><!-- --></div>
</div>
请记住,我有几个这样的代码块与同一个类。 vaUID [index]的示例值将是xxxxxx。
感谢您让我在正确的轨道上。我现在已经有了这个代码,但它似乎仍然给我带来了问题。 '$( '用户。信息a.element_username。') \t .filter(函数(){ \t \t返回$(本)。html的()的indexOf(vaUID [指数])> -1; \t} ) \t .siblings(“DIV”) \t的.html(“streaming ' + data.stream.game + '”);' – superzilla
我想通过检查,我复制一个用户ID href属性的最后几个数字来找到正确的元素。这段代码嵌套在一个。每个通过用户ID(vaUID [index])迭代的语句,一个例子是xxxxxx)和twitch.tv用户名(用户[index]) – superzilla