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

  • Home
  • SEARCH
  • 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 3872820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:58:02+00:00 2026-05-19T21:58:02+00:00

Is there a selector or function in JQuery that allows to select the current

  • 0

Is there a selector or function in JQuery that allows to select the “current position in the document”?

For example if I use

<script>document.write("test");</script>

the output will be placed in the HTML document at the “position” where this “code” stands. But jQuery always requires a special selector. Of course I could be using a “marker div” with a unique selector, but is it also possible to insert HTML with JQuery right at the place where where the JQuery expression stands?

I tried

<script>$(this).after("test");</script>

but this it’s not working. Help would be very much appreciated how this can be solved. Thank you!

EDIT:

Regarding the question below: The Idea is not to directly print out something with document.writeln (it was more meant as an example) but to determine the current “position” in the document with jQuery (and than starting from that position on with “navigation/traversal” of elements by using the jQuery functionality.

Maybe this can be called a “relative traversal of elements starting from the current position on in the DOM Tree”?

<div>Position1</div>
<div>Position2</div>
<script> HOW TO GET THIS POSITION WITH JQUERY (SEE NOTES BELOW) TO FURTHER NAVIGATE FROM HERE ON (RELATIVELY) TO THE PREVIOUS OR NEXT ELEMENT</script>
<div>Position3</div>
<div>Position4</div>

NOTES: The script tag with the jQuery statements will be inserted dynamically in the document and what I am interested in is, to be able to navigate from this position on in the document with jQuery. In the script Tag I might call something like “WRAP THE NEXT HTML ELEMENT WITH A TAG VIA JQUERY” or “GIVE ME THE NEXT HTML ELEMENTS VALUE-ATTRIBUTE”. As stated above it is possible to insert a “marker div” to determine the position but the question is, if JQuery is “autonomically” able to determine it’s position in the DOM-Tree (to start navigation in a “relative manner” from there on).

  • 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-19T21:58:03+00:00Added an answer on May 19, 2026 at 9:58 pm

    $(“script:last”) seems to work for all modern browsers (except IE)

    <html>
    <head>
      <title>test</title>
      <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.5.min.js"></script>
    </head>
    <body>
      <script type="text/javascript">
        document.write($("script:last").text());
      </script>
      <script type="text/javascript">
        document.write("---");
        document.write($("script:last").text());
      </script>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a case insensitive version of the :contains jQuery selector or should I
I am trying to write a jQuery plugin, that can be applied to a
I'm building a slideshow in jQuery that allows the user to see four images,
There is a conversion process that is needed when migrating Visual Studio 2005 web
There is a field in my company's Contacts table. In that table, there is
I have a table cell in the footer that allows the user to turn
A problem I regularly come across writing javascript using jQuery is that when a
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There is previous little on the google on this subject other than people asking

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.