[英]check to see a child div has certain link in a parent DIV
<div id="posts">
<table>
<tr>
<td>
<div id="name" class="enabled"><a href="123.com/abc">User1</a></div>
</td>
<td>
<div id="post-content">
Hello
<div id="load">
</div>
</div>
</td>
</tr>
</table>
<br><br>
<table>
<tr>
<td>
<div id="name" class="enabled"><a href="123.com/user2">User2</a></div>
</td>
<td>
<div id="post-content">
Hello too
<div id="load"></div>
</div>
</td>
</tr>
</table>
</div>
How can i use jQuery/Javacript to find link with " abc " inside #name div of #posts table . 我如何使用jQuery / Javacript在#posts表的 #name div中查找带有“ abc ”的链接。
and after locating it (the link with abc). 并找到它之后(带有abc的链接)。 jQuery will add html content to #post-content #load div of that table that has link with "abc" inside ,using the html(); jQuery会使用html();将html内容添加到该表的 #post-content #load div中,该表的内部带有“ abc”链接 。 function in jQuery. jQuery中的功能。
that means after adding my code will look like this : 这意味着添加我的代码后将如下所示:
<div id="posts">
<table>
<tr>
<td>
<div id="name" class="enabled"><a href="123.com/abc">User1</a></div>
</td>
<td>
<div id="post-content">
Hello
<div id="load">
Some stuff is added here using html()
</div>
</div>
</td>
</tr>
</table>
<br><br>
<table>
<tr>
<td>
<div id="name" class="enabled"><a href="123.com/user2">User2</a></div>
</td>
<td>
<div id="post-content">
Hello too
<div id="load"></div>
</div>
</td>
</tr>
</table>
</div>
while the #name with no link with "abc" which is the link with "user2" will not be affected or modifeid. 而没有与“ abc”链接(即与“ user2”链接)的#name 不会受到影响或修改。
How can i do this? 我怎样才能做到这一点?
I hope you understand. 我希望你明白。
Find #postcontent >#load
within this element 在此元素中找到#postcontent >#load
var x = $('a[href*="abc"]'); var b = x.parents('tr'); var c = b.find('#post-content > #load'); alert(c.html());
假设您修复了html并使用了类:
$('.name a[href*="abc"]').closest('tr').find('.load').html('Some stuff is added here using html()');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.