> 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-2.md).

# .toggleAttr()

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

#### **Usage Patterns**

#### **1. Toggle attribute existence**

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

If `hidden` exists → remove it\
If not → add it

***

#### **2. Toggle attribute with value**

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

If current value != "active" → sets\
If current value == "active" → removes

***

#### **3. Toggle multiple attributes**

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

Each key-value pair is toggled intelligently.
