JavaScript - How to createElement('a') and add innerText

Asked By Erik Little on 18-Aug-06 04:52 PM
Can someone show me how to create an 'a' element and append it to a div tag?
thanks
erik
<body onload="sneakInLink()">
<script type="text/javascript">
function sneakInLink(){
var myLink = document.createElement('a');
var href = document.createAttribute('href');
myLink.setAttribute(href,'http://www.afcc1.com');
myLink.innerText ="Go here";
var spanAppend = document.getElementById('myDivLink');
spanAppend.appendChild(myLink);
{
</script>
Asked By Sushila Patel on 18-Aug-06 05:09 PM
<script type="text/javascript"> 
function sneakInLink()
{ 
var myLink = document.createElement('a'); 
var href = document.createAttribute('href'); 
myLink.setAttribute('href','http://www.afcc1.com'); 
myLink.innerText ="Go here"; 
var spanAppend = document.getElementById('myDivLink'); 
spanAppend.appendChild(myLink); 
} <= ***here you were using {***
</script> <body onload="sneakInLink()"> 
<div id="myDivLink"></div>***<= here was the tag missing?***
</body>

Four eyes are better than two i guess

Asked By Erik Little on 18-Aug-06 05:12 PM
:)
thanks
erik
Ali replied to Sushila Patel on 04-Nov-10 03:45 AM
Sushila!
why you have created attribute on document level although the code is running fine without this line of code? I need to understand.
var href = document.createAttribute('href'); 
a replied to Erik Little on 04-Jul-11 09:24 AM
That line can be freely omitted.
help
Xml / Xslt 06-Jun-13 10:29 AM Hi, I am doing xml parsing using javascript as below. function ChangeParentNodeName() { var oXmlDom = new ActiveXObject("Msxml2.DOMDocument"); / / new ActiveXObject("Microsoft.XMLDOM"); var documentElement.selectSingleNode("AssetAllocation"); var oAttrs = oFirstChildNode.attributes var oNewXmlNode = null; var oAttr = null; oNewXmlNode = oXmlDom.createElement("NewAssetAllocation") for (var i = 0; i < oAttrs.length; i++) { oAttr = oXmlDom.createAttribute(oAttrs.item(i).name) oAttr.value = oAttrs.item(i).value oNewXmlNode.setAttributeNode(oAttr) } var oChildNodes Xslt, Xml, Percentage description: What is wrong here Hi, I am doing xml parsing using javascript as below. function ChangeParentNodeName() { var oXmlDom = new ActiveXObject(Msxml2.
why we use document.createElement what is meaning with a link to a nice W3C DOM tutorial http: / / www.eggheadcafe.com / forums / ForumPost.asp?ID = 47053&INTID = 3 keywords: JavaScript javascript description: javascript why we use document.createElement what is meaning 06-Jun-13 10:29 AM
How do I set a textbox readonly through Javascript? Use this. . document.Form.TextBox.Disabled = true; try with textbox.attributes.add("readonly", "readonly"); keywords: TextBox, Javascript JavaScript, JavaScript Textbox, Box, textbox readonly description: Textbox ReadOnly through Javascript How do I set a textbox readonly through Javascript 06-Jun-13 10:28 AM?
Javascript provides you an Escape function that converts the special characters to equivalent hexadecimal representation. Sample Escape function is as below: Document.Write Escape(stringwithSpecialCharacters) Related FAQs Use UnEscape function in Javascript to get the Special Characters After you have received the escaped special character string, you the Unescape function to get the actual contents How to Escape the Special Characters in Javascript? ( 986 Views ) keywords: Document, Write, Escape, special, characters, special, characters, Javascript, hexadecimal description: Javascript provides you an Escape function that converts the special characters to equivalent hexadecimal representation.
Javascript using in ultrawebgrid control? Did you try the method mentioned in the previous Post? http: / / www.eggheadcafe.com / community / aspnet / 3 / 10223058 / how-to-use-javascript-in-ultrawebgrid.aspx keywords: JavaScript Javascript, Javascript description Javascript using in ultrawebgrid control Javascript using in ultrawebgrid control 06-Jun-13 10:15 AM
how to update value in array for new selected array for selected element try this URL http: / / www.pageresource.com / jscript / jarray.htm keywords: JavaScript javascript, change value, javascript, array description: javascript how to update value in array for new selected product 06-Jun-13 10:29
How to create a global class in javascript and make a function which keep in class .and access that function in any child this details for more details http: / / www.webdevelopersjournal.com / articles / jsintro3 / js_begin3.html keywords: class, JavaScript javascript, Check, global class, javascript description: javascript How to create a global class in javascript and make a function which keep in class .and access that function in any child
how can i disable standard buttons of browser through javascript? unless you show your page as a "Chromeless" window with none of the menus and net is there any way to achieve this. You can disable the back button with javaScript <script language = "JavaScript" type = "text / JavaScript"> javascript:window.history.forward(-1); < / script> keywords: javascript JavaScript, JavaScript, Chromeless window, forward buttons description: disable standard buttons through javascript how can i
I searched for trim function in javascript but I did not find any reference. . . Is there any such function at all in JS? There is no built in function for trim unlike other languages in Javascript You could try this one out. . function trimString (str) { str = this ! = window? this : str; return JS does not have trim function?? Note::check the IP, belong to the same org?? javascript does not have but have in other scripts and languages. . . for your note :-) quite possible end of post end of post Here are some useful links of trimming function in javascript http: / / snippets.dzone.com / posts / show / 701 http: / / www.codestore.net / store.nsf / unid / BLOG-20060313 / http: / / blog.taragana.com / index.php / archive / how-to-trim-in-javascript / http: / / www.aspdev.org javascript / javascript-trim / Use this example / / Trims the controls value. function Trim(str) { while (str.substring