Reputation: 20916
<div class="pm1"><span class="from"><span class="plusminus" class="pm plus">TEXT1...
<div class="pm1"><span class="from"><span class="plusminus" class="pm plus">TEXT2...
then
$(document).ready(function () {
$(".pm1").click(function () {
and now I would like to get clicked span by class = plusminus
but I don't know how to get it , i have tried like $(this).find(xxx)
but does not work.
What can I do?
EDIT.
I changed id to class
Upvotes: 0
Views: 68
Reputation: 151
You can use this to find your element
$(this).find($("span")).find(".plusminus")
Upvotes: 1
Reputation: 6933
So to find the class .plusminus inside the clicked .pm1 you should use this
$(document).ready(function () {
$(".pm1").click(function () {
var plusminus = $(this).find('.plusminus');
//rest of your code
});
});
Upvotes: 2
Reputation: 238
Try This
$(document).ready(function (){
var click_span;
$(".pm1").click(function (){
click_span = $(this).find('.plusminus');
alert(click_span);
}
}
This will give you object of the span,
Upvotes: 1
Reputation: 803
You can get the html of grand child (id = plusminus) of the clicked element in two ways.
For example...
$(".pm1").click(function () {
// Method 1 (If you know the id of grand child)
console.log($(this).find("#plusminus").html());
// Method 2 (If you know the structure but dont know the element)
console.log($(this).find("span span").html());
});
If you want to execute it directly, then just call the below code:
$("#plusminus").click(function () {
// Your code goes here
});
Upvotes: 1