Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE not like DOM method

Status
Not open for further replies.

tester321

Programmer
Mar 13, 2007
150
CA
Hi, in FF everything works fine, in IE not :(

any thoughts, i've tinkered with it and can't seem to make IE happy:

var divQ = document.getElementById("div1Question");

// alert below is correct in syntax
alert("<a name=\"#Question" + strWsb.substring(3) + "\"></a>" + _strQuestion)

// below i get an unhandled exception error
divQ.innerHTML = "<a name=\"#Question" + strWsb.substring(3) + "\"></a>" + _strQuestion

//can make it here in FF not in IE
alert('made it here');



///////// Thanks
 
here is some more code:


I tried to create the inline attribute of name for the a tag on the fly and use:

var divContainer = document.createElement("a");

divContainer.setAttribute('name', '#Question'+strWsb.substring(3));

still without luck, any suggestions?
 
Have you tried using the String method anchor()?
Code:
var anchorName = "#Question" + strWsb.substring(3);
var anchorStr = "_strQuestion";
divQ.innerHTML = anchorStr.anchor(anchorName);

I am not sure that will give you what you want, but I figure it is worth a try. There is also the link() method which builds the <A href="linkURL">label</A> like this:

"label".link("linkURL");

Einstein47
For best results: hand wash in cold, tumble dry low.
For not so good results: drag through puddles, pound on rocks, air dry on tree branch.
[&#91;]Starbase47.com]
 
Thanks for help, i'll fiddle with both ideas. thanks again
 
The problem you are having is somewhere else, I'm personally thinking your DIV doesn't exist yet.

Here is some sample code that will assign an anchor innerHTML to a div:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">[/URL]
<html>
<head>
</head>
<body>
<div id="helloDiv"></div>
</body>
</html>
<script type="text/javascript">
   var obj = document.getElementById("helloDiv");
   obj.innerHTML = "<a href='[URL unfurl="true"]http://www.google.com'>Click[/URL] Link</a>";
</script>

Are you sure that an error isn't popping up in your javascript console in Firefox??

[monkey][snake] <.
 
Ive also found that using double quotes for the innerHTML gives me problems it prefers single quotes.

So i would change it to
Code:
obj.innerHTML = '<a href="[URL unfurl="true"]http://www.google.com">Click[/URL] Link</a>';

plus the HTML code should use double quotes for attributes anyhow.

just my 2pence :)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top