Home > UI/UX Development > jQuery > jQuery: Difference between parent(), parents() and parentsUntil() methods.

jQuery: Difference between parent(), parents() and parentsUntil() methods.

This post was most recently updated on September 26th, 2017

Definition:

  • parent() – Use this method to get direct parent element of the current selected element.
  • parents() – Use this method to get all parent elements of the current selected element.
  • parentsUntil() – Us this method to get all ancestor elements between the selector and the parameter you have selected in the parentsUntil() method. In this method parameter inside the parentsUntil(‘#parent1’) is essential part, if you missed to use parameter it will work like parents() method.

See the difference between these methods with example given below:

HTML:

CODE:

Output:

parent

Explanation: In the above example see there are green colour box with paragraph with four other boxes with a specific border colours and just below to that there are four buttons.

Now check the difference between each buttons.

When you click on parent() button it will set yellow background colour to direct parent of green box which in purple colour border.

parents() method

When you click on parents() button it will set yellow background colour to all parent elements of the green colour box till the body.

When you click on parentsUntil(parameter) button it will set yellow background colour up to the black border colour box because we have given parameter “parentsUntil(‘#parent1’)” and “#parent1” is a blue border box.

parentsUntil() method

Now click on last button parentsUntil() it will behave like parents() method because we have not given any parameter in the parentsUntil() method.

Click here to check all these methods in DEMO page

 

This Article is TAGGED in , , , . BOOKMARK THE permalink.

17 thoughts on “jQuery: Difference between parent(), parents() and parentsUntil() methods.

  1. Thanks for a marvelous posting! I definitely enjoyed reading it, you can be
    a great author. I will remember to bookmark your blog and will eventually come back
    sometime soon. I want to encourage you to continue your great
    posts, have a nice weekend!

  2. I’m not that much of a internet reader to be honest but your sites really nice, keep it up!
    I’ll go ahead and bookmark your website to come back in the future.
    All the best

  3. What’s up colleagues, how is all, and what you want to
    say regarding this piece of writing, in my view its actually remarkable designed for me.

  4. Hello there, just became aware of your blog through Google, and found that it is
    truly informative. I am going to watch out for brussels. I’ll appreciate if you continue this in future.
    Many people will be benefited from your writing.
    Cheers!

  5. I have fun with, lead to I found just what I used to be looking for.
    You have ended my 4 day long hunt! God Bless you man. Have a nice day.
    Bye

  6. This piece of writing is truly a good one it helps new internet viewers, who are wishing for blogging.

  7. Admiring the hard work you put into your site and in depth information you present.
    It’s nice to come across a blog every once in a while that isn’t the same unwanted rehashed information. Great read!
    I’ve saved your site and I’m including your RSS feeds to my Google account.

  8. You really make it seem so easy with your presentation but I find this topic to be actually something which
    I think I would never understand. It seems too complicated and very broad
    for me. I’m looking forward for your next post, I’ll try to get the hang of it!

  9. Hello there! Quick question that’s totally off topic. Do you
    know how to make your site mobile friendly?
    My weblog looks weird when browsing from my iphone4. I’m trying
    to find a theme or plugin that might be able to resolve this problem.
    If you have any suggestions, please share. Cheers!

  10. Hey! I’m at work surfing around your blog from my new apple iphone!
    Just wanted to say I love reading through your blog and look forward
    to all your posts! Keep up the outstanding work!

  11. I was curious if you ever thought of changing the structure of your website?

    Its very well written; I love what youve got
    to say. But maybe you could a little more in the way of content so people
    could connect with it better. Youve got an awful lot of text for only having one or
    2 pictures. Maybe you could space it out better?

  12. Excellent post. Keep posting such kind of info on your blog.
    Im really impressed by it.
    Hey there, You’ve performed a fantastic job. I will definitely digg it and personally suggest to my friends.
    I’m confident they’ll be benefited from this website.

  13. I have read so many content regarding the blogger lovers however this article is really a good post,
    keep it up.

  14. Magnificent web site. A lot of useful info here.
    I’m sending it to some friends ans also sharing in delicious.
    And of course, thanks on your sweat!

  15. Aw, this was a really nice post. Spending some time and actual effort to
    make a top notch article… but what can I say… I hesitate
    a whole lot and don’t seem to get anything done.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">