how to get span text from inner tags using jQuery

I want to get the span text using jQuery so my html code is like below

Note :- actually this logic was in table data so I given example code only.

<div class="strategiesddata">
<div class="strattabletodivmobright">
<p class="stategybuysellchkbox clearfix">
<span class="BUY active" name="spbuy">B</span>
<span class="SELL " name="spsell">S</span>
</p></div>

<div class="strattabletodivmobright">
<p class="stategybuysellchkbox clearfix">
<span class="BUY " name="spbuy">B</span>
<span class="SELL active" name="spsell">S</span>
</p></div>
</div>

In the above html code I have two active, buy or sell div’s so my query is if it active span then I should take that span text

ex:- From first div B and next div S text I should take

For this I have written jQuery like this

$(".strategiesddata").each(function () {
 t = $(this);
var tst = t.find(".stategybuysellchkbox").closest(".active").html();
});

And

$(".strategiesddata").each(function () {
 t = $(this);
var tst = t.closest(".stategybuysellchkbox").find("span[.active]").html();
});

But I’m getting the value is undefined Suggest me where I did the mistake and how to achieve this?

>Solution :

Your jQuery statement is wrong, try this.

var tst = $(".stategybuysellchkbox").find(".active").text();

Leave a Reply