Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading