tags:

views:

42

answers:

3

Hi, I've got some 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>

The HTML is a single item from a treeview created by Telerik. The real data here is that "Offshore" has an id of "41393".

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

+5  A: 

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 only have one t-in element, otherwise, you have have to replace the first line in my code with how you select the element yourself.

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

mkoryak
I'm not a Jquery expert... but... I thought I have to use `parent` twice? Am I wrong?
Cristian
I voted this up, however I would suggest using `$in.closest(".t-item")` instead of `parent`.
karim79
may i ask why? ?
mkoryak
@mkoryak - admittedly I don't think there's much of a difference, I just prefer using `closest` to achieve that as it reads better (to me at least).
karim79
A: 

How about this:

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

I'm assuming that all you want is the value of the Offshore element from a large tree of elements.

Bradley Mountford
A: 

Thanks for the suggestions guys, here is what I ended up with.

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

where e is the element Telerik gave me.

Frode Lillerud