Frode Lillerud
Frode Lillerud

Reputation: 7394

Find element using jQuery

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?

Upvotes: 4

Views: 765

Answers (3)

Frode Lillerud
Frode Lillerud

Reputation: 7394

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.

Upvotes: 0

Bradley Mountford
Bradley Mountford

Reputation: 8273

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.

Upvotes: 0

mkoryak
mkoryak

Reputation: 57918

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

Upvotes: 5

Related Questions