<...">

Find an item using jQuery

I have HTML that looks like this.

<li class="t-item t-first"> <div class="t-top"> <span class="t-icon t-plus"></span> <span class="t-in">Offshore</span> </div> <input type="hidden" value="41393" name="itemValue" class="t-input"> </li> 

HTML is one element from a tree created by Telerik. The real data here is that "Offshore" has the identifier "41393".

From the Telerik code, I get a span element with the t-in class, but I cannot get an ID value from it. How can I use jQuery to find the value of a hidden input type?

+4
source share
3 answers

how about this:

 var $in = $(".t-in"); var text = $in.text(); //offshore var val = $in.parent(".t-item").find("input.t-input").val() //41393 

this sorta works if you have only one t-in element, otherwise you will have to replace the first line in my code with the way you select the element yourself.

You need to provide more information, but this is the best I could do with what you gave

+5
source

How about this:

 var offShoreId = $("span.t-in").each(function() { if ($(this).val() == "Offshore") return $(this).parent().next().val(); } 

I assume that all you need is the value of the Offshore element from the large tree of elements.

0
source

Thanks for the suggestions guys, that’s what I ended up with.

 $(e.item).parent().find('input').val(); 

where e is the element that Telerik gave me.

0
source

Source: https://habr.com/ru/post/1309791/


All Articles