Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6318661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:39:56+00:00 2026-05-24T15:39:56+00:00

In jQuery, let’s say we have 2 ways to navigate through the DOM elements;

  • 0

In jQuery, let’s say we have 2 ways to navigate through the DOM elements;

  1. Through the use of CSS colon selectors (e.g. var x = $("#someElement:after"))
  2. Through the jQuery functions (e.g. var x = $("#someElement").prev())

Now my questions are:

  1. Is the return type same in both the cases?
  2. What is the difference in navigating through the DOM in both the
    approaches?
  3. Can we apply the same jQuery function to the result of both these
    statements? E.g. x.css("someProp","someVal")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:39:57+00:00Added an answer on May 24, 2026 at 3:39 pm

    I’m not sure that “:after” exists but other than that:

    1) The return type will be exactly the same for either (So long as its a valid selector)

    2) The difference is fairly slight, its mostly about how you prefer do to things and in certain cases the “:first” may not be exactly what you want, in a loop for example. There are arguments about which has the best overhead but I don’t know enough to comment.

    3) Absolutely, as the return type is exactly the same (A jQuery element) you can use them in exactly the same way.

    E.G:
    $(“#Test”).parent();
    would return exactly the same as
    $(“#Test:parent”);

    Example:
    http://jsfiddle.net/HenryGarle/2qcpK/

    <div id="Parent1">
        <div id="Test1">Text</div>
    </div>
    
    <div id="Parent2">
        <div id="Test2">Text</div>
    </div>
    
    
    // replaces the content of Test1's parent
    $("#Test1").parent().html("New Parent 1 content");
    
    // replaces the content of Test2's parent
    $("#Test2:parent").html("New Parent 2 content");
    

    This would result in the DOM looking like:

    <div id="Parent1">
        New Parent 1 content
    </div>
    
    <div id="Parent2">
        New Parent 2 content
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some kind of problem with jQuery selectors. Let's say i want to
Let's say I have form looks like First: Use jQuery to display data like
Let's say I have this jQuery extension method: $.fn.foobar = function() { var clone
Let's say I have the following jQuery AJAX call: $.ajax({ type: POST, url: MyUrl,
i prefer jquery. let's say i have a string with , adam, lisa, john,
I have a basic jQuery selector question. Let's say I'm parsing JSON and generating
Let's say I use jQuery to load new content into a specific DIV element.
I have a question on jQuery $(document).ready Let's say we have a HTML page
Let's assume that we have simple jQuery code like the following: var $document =
I DO NOT WANT TO CREATE A JQUERY PLUGIN Let's say I have something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.