jQuery Tutorial


jQuery Example


jQuery References


jQuery Attributes Selectors References




In a jQuery some of the most important components we are using in DOM element are the properties or attributes assign by the element.

jQuery some most attribute are available on JavaScript. Following some common attributes...

  • tagname
  • classname
  • id
  • href
  • src
  • rel

following one element attributes are show...

<p align="center" lang="en" id="div1" class="div1" 
title="First Paragraph">Paragraph</p>

in this element tag name is p, and attributes is represent align, lang, id, class, title consists of value or name.

Get Attribute Value

This example is introduce by The attr() method can be used to get value of an attribute from the first element in the matched attributes.

<html>
<head>
   <script type="text/javascript" src="../jquery-1.8.0.min.js"></script>
   <script type="text/javascript">
   $(document).ready(function() {
      var title = $("p").attr("style");
      $("#div1").text(title);
   });
   </script>
</head>
<body>
  <div>
    <p align="center" style="background-color:#FF9933;font-family:Arial, 
	Helvetica, sans-serif;">This is first paragraph.</p>
    <div id="div1" title="This is a Attributes 
	of the above Paragraph."></div>
  </div>
</body>
</html>
Online Try This Code Your Self....   »

Understand above example

  • Declare Variable eg. var title
  • Assign declared Variable to the style Attributes of <p> tag eg.$("p").attr("style");
  • Display the <p> tag attributes eg.$("#div1").text(title);
  • <div> tag id="div1" find the style attributes are display.