How to get/set element attribute value in javascript

13 Dec

The .setAttribute(‘attributeName’,’content’) method is used to set content to the attribute and .getAttribute(‘atrributeName’)  method is used to get attribute value.


<!DOCTYPE html>
<meta id="description" name="description" 
content="Free Web tutorials" />
<meta name="keywords" content="HTML,CSS,XML,JavaScript" />
<meta name="author" content="Hege Refsnes" />
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<script type="text/javascript">
function setProductMeta(){
var metaDesc=document.getElementById("description")
var textValue = document.getElementById("attr-test")
 <a href="#" onclick="setProductMeta()" >Click set&get Attribute</a>
 <input type="text" name="attribute-test" id="attr-test" value="" />
Leave a comment

Posted by on December 13, 2012 in General, Javascript


Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: