Forum Moderators: open

Message Too Old, No Replies

insertBefore(element) not working in ie6 or 7

         

surrealillusions

5:49 pm on Oct 16, 2008 (gmt 0)

10+ Year Member



I have a script for validating form inputs (making sure they're filled in) using jquery. It uses insertAfter(element) to place the error label. This all works fine across all browsers, except, i need to put that error label before the input, and found out by using insertBefore(element), it worked, although only in Firefox.

the script didnt work at all in explorer 6 or 7, and found that this line was causing the problem. Does explorer not understand the insertBefore(element) at all?

Is there a way round it without re-writing the entire script?

Thanks

:)

Fotiman

1:52 pm on Oct 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How are you using insertBefore? Here's an example that works:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title>Untitled</title>
</head>
<body>
<span id="target">&lt;&lt; That was inserted before this!</span>
<script type="text/javascript">
window.onload = function () {
var target = document.getElementById('target');
var parent = target.parentNode;
var newNode = document.createElement('span');
newNode.appendChild(document.createTextNode('Hi there!'));
parent.insertBefore(newNode, target);
};
</script>
</body>
</html>

surrealillusions

1:56 pm on Oct 21, 2008 (gmt 0)

10+ Year Member



hi,

thanks for the reply.

Heres the part of the script that uses the insertBefore(element)

if ( !this.labelContainer.append(label).length )
this.settings.errorPlacement
? this.settings.errorPlacement(label, $(element) )
: label.insertAfter(element);
}

Fotiman

5:50 pm on Oct 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't see any call to insertBefore in that example.

surrealillusions

12:36 pm on Oct 22, 2008 (gmt 0)

10+ Year Member



d'oh..it has the insertAfter instead of insertBefore

sorry

:)