getAttribute
method is used to get the value associated with the attribute.
Open above file in browser, you can able to see the value of title attribute in alert box.
Syntax
element.getAttribute(attributeName);
Ex:
<p
title="Good Morning" id = "para1"></p>
Following
statements are used to get the value associated with title attribute.
var
element = document.getElementById("para1");
var
titleVal = element.getAttribute("title");
getAttribute.html
<!DOCTYPE html> <html> <head> <title>Get Attribute</title> </head> <body> <p title="Good Morning" id="para1"></p> <script> var element = document.getElementById("para1"); alert(element.getAttribute("title")); </script> </body> </html>
Open above file in browser, you can able to see the value of title attribute in alert box.
No comments:
Post a Comment