.GET (). Prop () does not work together jquery

So the context is this:

I have some favorite inputs with cities, when the values ​​change, I need to find the identifier of the parent node 9 levels above this selected input, then split it, and then get the last part of the array by split.

I know that the identifier of the target node is in the format "someName_SomeNumber", for example, "node_1234".

I tried to do this using this function:

$("select[name*=id_city_]").change(function(){ alert($(this).parents().get(8).prop("id").split("_").last()); }); 

everything works fine if I execute "$ (this) .parents (). get (8)", but when I try to get a support id, it says prop is not a function.

early.

+5
source share
1 answer

get() get the base native DOM node, which does not have a prop method.

Do you want eq()

 $(this).parents().eq(8).prop("id").split("_").pop() 

or just use your id property

 $(this).parents().get(8).id.split("_").pop() 

Also note that last() is a jQuery method, to get the last element in an array in your own way, you pop from the end

+5
source

All Articles