> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/manipulation/.toggleattr-1.md).

# .toggleAttr()

Toggles the presence or value of attributes.

## `$(selector).toggleAttr()`

### Usage Patterns

{% stepper %}
{% step %}

## Toggle attribute existence

```js
$('#box').toggleAttr("hidden");
```

If `hidden` exists → remove it\
If not → add it
{% endstep %}

{% step %}

## Toggle attribute with value

```js
$('#box').toggleAttr("data-mode", "active");
```

If current value != "active" → sets\
If current value == "active" → removes
{% endstep %}

{% step %}

## Toggle multiple attributes

```js
$('#box').toggleAttr(
    "data-size", "xl",
    "draggable", "true",
    "contenteditable", "true"
);
```

Each key-value pair is toggled intelligently.
{% endstep %}
{% endstepper %}
