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 582669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:42:42+00:00 2026-05-13T14:42:42+00:00

If I do this var domElement = $(#id); and the returned element is a

  • 0

If I do this

var domElement = $("#id");

and the returned element is a div tag,

How can I then do something like

domElement.$('div a:nth-child(3)').after(somehtml);

This is an example where I want to add some HTML after the third link under that “domElement” div.

The above doesn’t seem to work. I have numerous examples where I have already selected a certain element from the entire page HTML and I then want to work inside the “context” of that element.

In 90% of cases I want to continue jQuery selection, traversion and manipulation from a previously selected DOM element from a page not from the whole page like $(..) does.

  • 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-13T14:42:42+00:00Added an answer on May 13, 2026 at 2:42 pm

    You want .find(): http://api.jquery.com/find/

    var domElement = $("#id");
    domElement.find('div a:nth-child(3)').after(somehtml);
    

    If you plan on chaining this with multiple sub-selectors on domElement, end each use of .find() with .end():

    $("#id")
      .find('div')
        .click(function() { alert("#id div"); })
        .find('a.my-class1')
          .click(function() { alert("#id div a.clickable"); })
          .end() // stop working with 'a.my-class1'
        .find('a.my-class2')
          .click(function() { alert("#id div a.my-class2"); }) 
          .end() // stop working with 'a.my-class2'
        .end() // stop working with 'div'
      .click(function() { alert("#id"); });
    

    Conceptually, you’re descending deeper into the DOM with .find(), and ascending back up the DOM with .end(). Technically “descending” and “ascending” aren’t correct because you can also traverse first up then back down with functions like .parent() or .closest(), both of which can be terminated with .end() to return to the original selector:

    $("#id")
      .parent()
        .click(function() { alert("I'm #id's parent!"); })
        .end()
      .click(function() { alert ("back to #id"); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have something like this: var xmlStatement:String = xmlObject.node[3].@thisValue; What mystery function do
I have code like this: var newMsg = new Msg { Var1 = var1,
This is a really basic question but... I have some code like this var
Is is better to do a joined query like this: var employer = (from
In JavaScript, you can do this: var a = null; var b = I'm
I have this code: var $msg = jQuery('<div></div>') .hide() .appendTo(document.body) ; if ($msg.is(:hidden)) {
I have some code doing this : var changes = document.getElementsByName(from); for (var c=0;
I know almost nothing about linq. I'm doing this: var apps = from app
for example this code var html = <p>This text is <a href=#> good</a></p>; var
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]

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.