39
eldamir
8y

So, should I refactor this into a .greatGreatGrandParent() method, or should I just go hang myself?
(Thanks former colleague for this gem)

Comments
  • 1
    Can't you do $(this).parents('selector')
  • 2
    quit. next question.
  • 0
    @itsdaniel0 you'd think ;)
  • 1
    Mmh probably hang yourself, good luck
  • 1
    Option 3.
    Find colleague, torture him then hang him.
  • 0
    Not really used jquery. But is there a way you can broadcast an event, and let the great grandmother or whoever listen to it and handle it by itself?
  • 1
    @ronakkaria that would be one way to do it. Plenty of other good solutions also. But all our 40k lines of JS looks like this mess, and now I have to maintain it 😩
    The great part is that I have absolutely no way of knowing what these parents refer to. The static html is no help, because it is all changed dynamically through JS
  • 0
    @eldamir Not to turn this rant into a more than just an outlet of frustration, but what are the other ways of doing? A scenario like this pops up in most of my projects
  • 0
    @ronakkaria apart from all the fancy view libraries, just using a selector with an id or class. Something that names and describes what is being found. Probably a comment to explain it. Naming conventions for nested elements could be an easy way to get some structure as well. Many easy improvements
  • 1
    Try to use "closest(...)":
    https://api.jquery.com/closest/

    Or even better: Switch to Angular ;)
Add Comment