---
url: 'https://metadrop.net/es/articulos/jquery-once-un-metodo-para-anadir-behaviors-una-sola-vez'
title: 'jQuery .once() un método para añadir behaviors una sola vez'
author: 'Agustin Gómez'
date: '2017-01-17T10:55:44+00:00'
updated: '2026-08-04T08:09:33+00:00'
type: article
summary: 'Implementación de un método que necesitamos conocer bien para una correcta ejecución de JS en Drupal.'
tags:
  - Drupal
  - jQuery
  - 'Drupal 7'
published: true
og:
  determiner: Automatic
  site_name: Metadrop
  'image:alt': 'jQuery .once() un método para añadir behaviors una sola vez'
  street_address: 'Calle Manuel Luna, 12, 3 Dcha'
  locality: Madrid
  region: Madrid
  postal_code: '28020'
  country_name: España
  email: hola@metadrop.net
  phone_number: '910053180'
schema:
  '@context': 'https://schema.org'
  '@graph':
    -
      '@type': Article
      '@id': 'https://metadrop.net/es/articulos/jquery-once-un-metodo-para-anadir-behaviors-una-sola-vez#article'
      name: 'jQuery .once() un método para añadir behaviors una sola vez'
      headline: 'jQuery .once() un método para añadir behaviors una sola vez'
      description: 'Implementación de un método que necesitamos conocer bien para una correcta ejecución de JS en Drupal.'
      about:
        - Drupal
        - jQuery
        - 'Drupal 7'
      datePublished: '2013-12-09T00:00:00+0100'
      dateModified: '2026-08-04T10:09:33+0200'
      author:
        '@type': Person
        name: 'Agustin Gómez'
      publisher:
        '@type': Organization
        '@id': 'https://metadrop.net/#organization'
      mainEntityOfPage: 'https://metadrop.net/es/articulos/jquery-once-un-metodo-para-anadir-behaviors-una-sola-vez'
    -
      '@type': Organization
      '@id': 'https://metadrop.net/#organization'
      url: 'https://metadrop.net/'
      name: Metadrop
      sameAs:
        - 'https://www.drupal.org/metadrop'
        - 'https://twitter.com/metadrop'
        - 'https://asociaciondrupal.es/partner/metadrop'
        - 'https://www.linkedin.com/company/metadrop'
      logo:
        '@type': ImageObject
        url: 'https://metadrop.net/themes/custom/mdrop_radix/logo-metadrop-500-500.jpg'
        width: '500'
        height: '500'
    -
      '@type': ItemPage
      '@id': 'https://metadrop.net/es/articulos/jquery-once-un-metodo-para-anadir-behaviors-una-sola-vez'
      breadcrumb:
        '@type': BreadcrumbList
        itemListElement:
          -
            '@type': ListItem
            position: 1
            name: Inicio
            item: 'https://metadrop.net/es'
          -
            '@type': ListItem
            position: 2
            name: 'Artículos expertos sobre Drupal y tecnología'
            item: 'https://metadrop.net/es/articulos'
      publisher:
        '@type': Organization
        '@id': 'https://metadrop.net/#organization'
---
 1. [Artículos](https://metadrop.net/es/articulos)
 
  

# jQuery .once() un método para añadir behaviors una sola vez

Lunes 09 de Diciembre de 2013

 

 



Implementación de un método que necesitamos conocer bien para una correcta ejecución de JS en Drupal.



   



## Artículo completo:

[jQuery .once() method for adding behaviors once](https://drupal.org/update/modules/6/7#jquery_once)

## Drupal 6.x:

```javascript
Drupal.behaviors.mybehavior = function(context) {
  $('input.mybehavior:not(.mybehavior-processed)', context)
    .addClass('mybehavior-processed')
    .each(function() {
      // Apply the MyBehaviour effect to the elements only once.
    });
};

```

## Drupal 7.x:

```javascript
Drupal.behaviors.mybehavior = {
  attach: function(context, settings) {
    $('input.mybehavior', context).once('mybehavior', function() {
      // Apply the MyBehaviour effect to the elements only once. 
      // For example
      $(this).click(function() {
        console.log('it works!');
      });
    });
  }
};
```



[Drupal](https://metadrop.net/es/articulos?text=Drupal)

[jQuery](https://metadrop.net/es/articulos?text=jQuery)

[Drupal 7](https://metadrop.net/es/articulos?text=Drupal%207)