JQuery.closest (); DOM intersection not up

Afternoon peoples.

I have a bit of a nightmare walking through a DOM tree. I have the following markup

http://pastie.org/999519 

... And I'm trying to move from input.save in the lower right part of the path to div.node ... This all works well with one copy of the markup, but if I duplicate it (obvisouly change the identifier of the topmost div.node and use jQuery. closest ('div.node') for the top of div.node, it will return the element below it not the element above it (which is correct). I tried using parent (), but there are also some warnings. Is there any is it contexyt that can be attached to the closest one to make it rise rather than down? or is there a better way to do this.

Thanks in advance.

Alex

PS It seems that stackoverflow did something weird for the markup! - I only tested it three times, and this is normal, but for some reason he stated it below

+4
source share
1 answer

First of all, you really need to use the identifier for the .save element, if you have more, and if so, then use the node prefix if you can, so $('input.save') ...

I am not sure what the problem is with your code. You say that it goes down when you want it to rise? He must rise.

From jQuery docs at http://api.jquery.com/closest/ :

Get the first ancestor element that matches the selector, starting from the current element and progressing up through the DOM tree

There may be some problem using .find() right after closest() . However, I do not think that would be a problem.

+1
source

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


All Articles