Development| HTML| JavaScript| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JavaScript createAttribute method 
 

In the HTML JavaScript we have one of the important method createAttribute which can be used to create the html tag's attribute dynamically.

 

JavaScript createAttribute method

                         

In the HTML JavaScript we have one of the important method createAttribute which can be used to create the html tag's attribute dynamically. We can create any attribute of the tag elements by getting the object of it and then we can add value for this attribute to that element by setting the property "nodeValue" to add the node we can use the method setAttributeNode( attributeName) .

 

 

 

 

 

Syntax: 

document_Object.createAttribute("attributeName");

Description of example code:

In our this example code we have created an input text with its default size and after this we have added a button with the following caption "Create & Add attribute". This button will call the JavaScript function create() as defined in between the script tag. In this function create() we have created an attribute "size" and set its value to the "15". Here is the full example code of the createAttributeExample as follows:

createAttributeExample.html

<html>
<body>
<script language="JavaScript">
function create(){
    var attribute = document.createAttribute("size");
    attribute.nodeValue = "15"
    document.getElementById("text").setAttributeNode(attribute); 
} 
</script>
<div style="background: #cf2255; width:'100%';" align="center">
  <font color="#ffffcc" size="12pt">
           <b>Create Attribute Example</b>
   </font>
</div>
<div style="background: green width:'50%';">
	<center>
		<input type="text" id="text" value="" />
		<input type="button" 
                       value="Create & Add attribute" 
                       onclick="create(); 
                       this.disabled=true;">
	</center>
</div>
</body>
</html>

Output:

When user click on the Create and Add attribute button it sets the text box size to 15 by removing the default value of size attribute.

Download Source Code

                         

» View all related tutorials
Related Tags: java javascript c attributes script reference object method sed remove ip attribute node move nat to ref e it alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.