I use PHP and jQuery. I'm trying to do some开发者_StackOverflow社区thing like this:
$(this + ' .my_child_class').html('test');
I have a dynamic list of elements and when click on a button I use "this" to get to the current element group.
The problem is that I want to get to the class "my_child_class" which is somewhere within the current element group. The jQuery above don't work.
The HTML could look like this:
<div class="item">
<div class="container">
<div class="my_child_class">Content</div>
</div>
<input type="submit" />
</div>
<div class="item">
<div class="container">
<div class="my_child_class">Content</div>
</div>
<input type="submit" />
</div>
I'm assuming this is happening in an event handler -- this
is a DOM element there, not a string. You probably want this:
$(this).find('.my_child_class').html('test');
You should put this code in your function:
$(document).ready(function() {
$("div.item > input").bind('click',function() {
$(this).prev().find('.my_child_class').html('test');
});
});
You can find the whole solution here : http://jsfiddle.net/PLm5a/1/
Regards.
Is this what you're after? Something like:
$(this).closest(".item").find(".my_child_class").html("test");
attached to the input button.
Without knowing what this
actually refers to, I suspect you need
$(this).find(".my_child_class").html("test");
You may want to take a look at the other Traversing functions, too, depending on your situation.
精彩评论