Friday, September 19, 2025
HomeLanguagesJavascriptBackbone.js trigger Event

Backbone.js trigger Event

Backbone.js trigger Event is used to invoke or callback the function for the given event or a space-delimited list of events. The subsequent arguments will be passed along to the event callbacks in order to trigger it.

Syntax:

object.trigger(event, [*args])

Parameter Values:

  • event: It is used to bind an object with an event.
  • args: It is used to pass values or arguments to the callback function.

Example: This example describes the trigger event in Backbone.js.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Backbone.js trigger Event</title>
    <script src=
        "https://code.jquery.com/jquery-2.1.3.min.js" 
        type="text/javascript">
    </script>
    <script src=
         type="text/javascript">
    </script>
    <script src=
         type="text/javascript">
    </script>
</head>
  
<body>
    <h1 style="color: green;">
        neveropen
    </h1>
      
    <h3>Backbone.js trigger Event</h3>
      
    <script type="text/javascript">
        var gfgVar = _.extend({
            title: 'neveropen',
            site:
`<a href="https://www.geeksforgeeks.org/">neveropen</a>`,
        }, Backbone.Events);
      
        gfgVar.on('gfgFunc', function () {
            document.write(`This is `
                + this.title
                + ` & is the triggered value for site is: `
                + this.site);
        });
      
        gfgVar.trigger('gfgFunc');
    </script>
</body>
  
</html>


Here, the _.extend() function is used to create a copy of all of the properties of the source objects over the destination object and return the destination object.

Output:

Trigger event

Example: This example describes the Backbone.js trigger Event using the <iframe> tag.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Backbone.js Event trigger Event</title>
    <script src="https://code.jquery.com/jquery-2.1.3.min.js" 
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
    <script src=
        type="text/javascript">
    </script>
</head>
  
<body>
    <h1 style="color: green;">
        neveropen
    </h1>
      
    <h3>Backbone.js trigger Event</h3>
      
    <script type="text/javascript">
        var gfgVar = _.extend({
            title: 'neveropen',
            site: `<iframe src=
                "https://www.geeksforgeeks.org/"
                height="200"
                width="400">        
        </iframe>`,
        }, Backbone.Events);
  
        gfgVar.on('gfgFunc', function () {
            document.write(this.title
                + ` website is placed inside the iframe<br>`
                + ` & is the triggered value for site is: <br>`
                + this.site);
        });
  
        gfgVar.trigger('gfgFunc');
    </script>
</body>
  
</html>


Output:

Trigger Event

Reference: https://backbonejs.org/#Events-trigger

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6665 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS