Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 1st, 2004, 07:30 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default innerHTML

Hi all,

Just a little one this but when I write this:

P4.innerHTML =""

I get an unknown runtime error! P4 refers to this in my HTML:

<P ID ="P4"></P>

I need a horizontal line to appear there. Any ideas?

interrupt

__________________
\'sync\' &lt;cr&gt;
The name specified is not recognized as an internal or external command, operable program or batch file.
 
Old July 1st, 2004, 07:33 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

What is the error?

Try document.getElementById('P4').innerHTML = '';

Is this line run before the element exists?

HTH,

Snib

<><
 
Old July 1st, 2004, 08:53 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes the line is run before the element exists, as I'm trying to use it to create the . Its a Set rather than a Get.

 
Old July 1st, 2004, 09:18 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

LOL.... Running the line before the element exists is not good.

Try placing your line in an onload function:

onload=function(){document.getElementById('P4').in nerHTML=""};

But, if you want to put it in there when the page loads, why don't you just directly add it?

<P></P>

HTH,

Snib

<><
 
Old July 1st, 2004, 09:25 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

LOL I agree but in this case I need to make an exception as I need the to appear onmouseover? Oh btw the error reads thusly: Unknown Runtime Error.



 
Old July 1st, 2004, 09:30 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

What browser are you using?

This should work....
Code:
<script type='text/javascript' language='javascript'>
var p1 = document.getElementById('para1');
function showHR()
{
 p1.innerHTML = '';
}
function hideHR()
{
 p1.innerHTML = '';
}
</script>
<button onmouseover='showHR()' onmouseout='hideHR()'>click</button>
<p id='para1'></p>
HTH,

Snib

<><
 
Old July 22nd, 2004, 02:18 PM
Registered User
 
Join Date: Jul 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

IE will not let you use certain tags in an innerHTML expression within <p> tags, e.g., , <h2 />, <p /> etc.

If you change your <p> tag to a <span> everything should work.

Even Snib's code should work then! :)

_Merrick





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem using innerHTML adfranklin BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 0 April 13th, 2007 01:13 AM
abusing innerHTML ophillip Javascript How-To 3 July 21st, 2005 02:21 AM
Getting InnerHtml ghari Javascript 3 January 3rd, 2005 12:06 PM
innerHTML problem higgsy Javascript How-To 2 August 7th, 2003 07:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.