How to change content of HTML DOM elements on jsp page from external javascript file ?

Posted on 2015-02-21
Last Modified: 2015-02-21
I have this jsp

<script type="text/javascript" src="abc.js"></script>
<div id=container></div>

Open in new window

contents of abc.js
document.getElementById("container").innerHTML="Some TEXt";

Open in new window

I want to set some text in <div> from external javascript file.
What mistake I am doing ?
Question by:Pradip Shenolkar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 10

Accepted Solution

Jeffrey Dake earned 500 total points
ID: 40623874
Your script is included at the top of your file and firing right away. At that point the container div is not rendered. You could move your JavaScript file farther down in the Dom, or change it to be wrapped in a window on load event and have your script fired on that event.

Author Closing Comment

by:Pradip Shenolkar
ID: 40623879
Thank you

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Clear input text 15 27
Use Mid in Html 6 23
AngularJS: ng-repeat 25 28
ExcelWebAddIn Connect to SQL database (Javascript or 7 29
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question