Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Javascript JavaScript getAdjacentText method

Related Tutorials


Share on Google+Share on Google+

JavaScript getAdjacentText method

JavaScript getAdjacentText method returns the text adjacent to the specified text element.

JavaScript getAdjacentText method


JavaScript getAdjacentText method returns the text adjacent to the specified text element.








If position value is beforeBegin then the returned text would be the text immediately before the textElement. If position is afterBegin  then the returned text would be the text after the start of the textElement but before all other content in the textElement. If  position is beforeEnd then the returned text would be the text before the end of the textElement but after all other content in the textElement and if position value is afterEnd then the returned text would be the text after the end of the textElement

Description of code

In the following sample code we have written some text paragraph and the text on which we want to apply the method getAdjacentText() we have shown in the italic manner. We have created a button "Get Adjacent" which calls the function getAdjacent() as defined in the JavaScript. This function takes the text element by using the method getElementById("element id") and it returns the text before the text element and write this returned text to the document. Here is the full source code getAdjacentTextExample.html as follows:


<script language="JavaScript">
  function getAdjacent() {
<div style="background: #cf2255; width:'100%';" align="center">
<font color="#05ff20" size="12pt">
<b>Focus Example</b>
<div style="background: #ffffcc; width:'100%';" align="center">
<p> &nbsp; </p>
<font color="#0000ff">
Rose India Technologies Pvt. Ltd. is a global services company that ensures maximum returns by providing quality software solutions and services. The Indian based company provides services to several reputed institutional clients, in the domain of IT and IT enabled Technologies. We help in understanding the client requirements and offer customized solutions in various specialized areas like Web based Technologies, Database Systems,<i id="italic"><b> Client Server Architecture </b></i>, E-commerce Solutions and Consultancy Services. Other services offered include Online Technical Tutorials, Content Development and Generation, Web solutions for B2B, B2C, C2C and Travel portals, Web Development, Promotion and Hosting, and Applications Service Provider Solutions.
<div style="background: #990999; width:'100%';" align="center">
<input type="button" value="Get Adjacent !" onclick="getAdjacent();"/>

Output :

Download Source Code



If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 29, 2009

Related Tutorials

Discuss: JavaScript getAdjacentText method  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image