473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

javascript not executed from the innerHTML

Hi,
I am trying to understand why this code does not work as expected.
FF shows the message twice; IE doesn't show the message at all.
What would be the right way to get the message displayed only once?
Please, help, thanks...
Jano
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language="javascript">
function test_of_innerhtml(){
document.getElementById('n1').innerHTML='<strong
onmouseout="javascript:alert(\'Hi\');">hi in</strong>';
}
</script>
</head>
<body>
<div id='n1' onmouseover="javascript:test_of_innerhtml();">hi</div>
<br />
<a
href="javascript:alert(document.getElementById('n1 ').innerHTML);">Show
innerHTML</a>
</body>
</html>

Dec 8 '06 #1
1 1829
ASM
Janooo a écrit :
Hi,
I am trying to understand why this code does not work as expected.
FF shows the message twice; IE doesn't show the message at all.
What would be the right way to get the message displayed only once?
Please, help, thanks...
http://stephane.moriaux.perso.wanado...nerHTML_danger

Try this and probably will you see what happens :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<style type="text/css">
div, strong { border:1px solid red; padding: 2px 8px; }
</style><head>
<title>Untitled Page</title>
<script language="javascript">
var i = j = 0;
function test_of_innerhtml(){
document.getElementById('n1').innerHTML='<strong
onmouseout="javascript:alert(\'Hi_\'+i);i++">hi in '+j+'<\/strong>';
j++;
}
</script>
</head>
<body>
<div id='n1' onmouseover="javascript:test_of_innerhtml();">hell o</div>
<br />
<a
href="javascript:alert(document.getElementById('n1 ').innerHTML);">Show
innerHTML</a>
</body>
</html>

When mouse leaves tag strong it leaves too the div reinserting a new
strong leaved as soon as created (2 tags strong in one).
To avoid double alert, probably with a counter could it be possible ?

--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Dec 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: zarroba | last post by:
Hi, I'm developing a webpage that is composed by several divs. These divs are supplied by the server depending on the user that made the request. Some of these divs require some javascript...
6
by: William Pierce | last post by:
Hi, I have an interesting problem that I am stuck on and was wondering if there might be others who can shed some light.... Basically, within an HTML page, I have a tag that looks as...
22
by: Christopher Nelson | last post by:
I have a little menu system which essentially takes HTML like: <div id='foo'></div> and retrieves foo.shtml from the server and inserts it inside the <div>. But sometimes I'd like foo.shtml...
8
by: Pratik Patel | last post by:
Hello, I used innerHTML to assign HTML content. but in my HTML page content have also some javascript function and it will run when page load. bu when HTML code assgin thru innerHTML then this...
3
by: jackson.rayne | last post by:
Hello, Another newbie question here. Let me explain my situation first. I have bought a 3rd party tool that runs a PHP script and gives me some HTML code which I can directly use in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.