Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



JavaScript - How to create Element

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 04-06-2009
Member
 
Join Date: Jun 2009
Posts: 309
JavaScript - How to create Element
  

I need to create an 'a' element and append it to a div tag. I had already made a script that dynamically adds checkboxes and hidden input type to a given page but the problem is it works with IE but not with FireFox. Could any one of make me how to do that?

Reply With Quote
  #2  
Old 04-06-2009
Member
 
Join Date: Feb 2009
Posts: 233
Re: JavaScript - How to create Element

When assigning some HTML to the innerHTML property of a DOM element, Internet Explorer performs some security text, especially if the inserted HTML contains javascript. To make your script with Firefox, you can try this :-



Quote:
function test(){

var hr =document.createElement("hr");
document.getElementById("thebody").appendChild(hr);

}
Or better you try this code create an 'a' element and append it to a div tag:-

Quote:
<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>
Reply With Quote
  #3  
Old 04-06-2009
Member
 
Join Date: Feb 2009
Posts: 391
Re: JavaScript - How to create Element

you have to use the javascript: prefix on the href for it to become an active javascript function caller. So this is how it should be:


Quote:
newlink = document.createElement('a');
newlink.setAttribute('class', 'signature');
newlink.setAttribute('href', 'javascript:showSignature(xyz)');
Reply With Quote
  #4  
Old 04-06-2009
Member
 
Join Date: Feb 2009
Posts: 192
Re: JavaScript - How to create Element

Create element Script code:-

Quote:
<html>
<body>
<script language="javascript">
function function1(){
var myElement = document.createElement('<hr>');
myBody.appendChild(myElement);

myElement = document.createElement('<Br>');
myBody.appendChild(myElement);

myElement = document.createElement('<Hr>');
myBody.appendChild(myElement);
}
</script>
<body id="myBody">
<button onClick="function1();">Put horizontal rule</button>
</body>
</html>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "JavaScript - How to create Element"
Thread Thread Starter Forum Replies Last Post
Unable to create share on WD Element USB connected with WD My book Live Duo Maq-Bool-Ji Hardware Peripherals 4 26-03-2012 10:59 PM
javascript get element by class GlassFish Software Development 5 06-03-2010 08:05 PM
How to set the value of a form element using Javascript? shivendra Software Development 4 07-02-2010 04:04 AM
Code to scroll to javascript element. sizzla Software Development 2 04-07-2009 10:13 PM
How do I know the width of an element through javascript? Conner Software Development 3 06-04-2009 11:29 AM


All times are GMT +5.5. The time now is 05:24 AM.