Solved

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

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

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

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 ?
0
Comment
Question by:Pradip Shenolkar
2 Comments
 
LVL 10

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:Pradip Shenolkar
ID: 40623879
Thank you
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now