Get or Set attributes of elements using .attr()

.attr()


Description: Get the value of an attribute for the first matched element or you can set one or more attributes for every element matched.


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>attr demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
      
    </head>
    <body>
      
      <p>Attribute will be added to this Paragraph</p>
      
      <script>
         
         bitsyCode.ready(function(){
            BitsyCode.attr('id', 'myParagraph'); //SET Attriute 'ID'
         })
         
      </script>
     
    </body>
    </html>

Preview:

Set Attribute

<p id="myParagraph">Attribute will be added to this Paragraph</p>

Retrieved Attribute

myParagraph
  • Usage

    • How to use:

      Get or Set attributes of elements using the .attr() method.

    • SET:

      bitsyCode("element").attr("attribute", "value");
    • GET:

      bitsyCode("element").attr("attribute");
  • Options

    • What options are there:

      There are no options for this method.

  • Returns

    • The GET returns the attribute value.
Share