Open In App

Backbone.js attributes View

Backbone.js attributes view are nothing but a hash of attributes which are set as HTML DOM element attributes on the view’s el. For example, (id, class, data-properties, etc.), or in other cases, a function that returns a hash.

Syntax: 



view.attributes

Parameters:

Example 1: The following codes demonstrate the view and attributes of Backbone.js.






<!DOCTYPE html>
<html>
  
<head>
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
</head>
  
<body>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
  
    <script type="text/javascript">
        var X = Backbone.View.extend({
            initialize: function () {
                document.write(this.tagName);
            }
        });
          
        var Y = new X({ tagName: "GeeksforGeeks!!!" });  
    </script>
</body>
  
</html>

Output:

 

Example 2:




<!DOCTYPE html>
<html>
  
<head>
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
</head>
  
<body>
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <button onclick="invoke()">Click me</button>
      
    <script type="text/javascript">
        var X = Backbone.View.extend({
            initialize: function () {
                var country;
                document.write(this.tagName, "<br>");
                document.write("Country Name= " + 
                    this.model + "<br>City Name= " + 
                    this.className);
            }
        });
  
        function invoke() {
            var Y = new X({
                tagName: "GeeksforGeeks!!!", 
                model: "INDIA", 
                className: "NOIDA"
            });
        }  
    </script>
</body>
  
</html>

Output:

 

Reference: https://backbonejs.org/#View-attributes


Article Tags :