Development| HTML| JavaScript| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
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.

 

 

 

 

 

Syntax: 

 textElement.getAdjacentText(position);

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:

getAdjacentTextExample.html 

 <html>
<body>
<script language="JavaScript">
    function getAdjacent() {
      document.write(document.getElementById('italic')
                   .getAdjacentText('beforeBegin'));
    }
</script>
<div style="background: #cf2255; width:'100%';" align="center">
<font color="#05ff20" size="12pt">
<b>Focus Example</b>
</font>
</div>
<center>
<div style="background: #ffffcc; width:'100%';" align="center">
<p> &nbsp; </p>
<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.
</font>
</p>
</div>
<div style="background: #990999; width:'100%';" align="center">
<input type="button" value="Get Adjacent !" onclick="getAdjacent();"/>
</div>
</body>
</html>

Output :

Download Source Code

                         

» View all related tutorials
Related Tags: java javascript c attributes script reference object method sed remove ip attribute node move nat to ref e it alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.