So the context is this:
I have some select inputs with cities, when the value changes I need to search for the ID of the parent node 9 levels above of that select input, then split it, and then get the last part of the array given by split.
I know the ID of the target node is in format "someName_SomeNumber" like "node_1234".
I've tried to do that on this function:
$("select[name*=id_city_]").change(function(){
alert($(this).parents().get(8).prop("id").split("_").last());
});
everything works great if I execute "$(this).parents().get(8)", but when I try to get the ID with prop it says that prop is not a function.
thanks in advance.
get()
get's the underlying native DOM node, which doesn't have a prop
method.
You want eq()
$(this).parents().eq(8).prop("id").split("_").pop()
or just use the native id
property
$(this).parents().get(8).id.split("_").pop()
Also note that last()
is a jQuery method, to get the last item in an array the native way, you pop
it off the end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With