Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you add data-toggle="dropdown" to an anchor

Tags:

jquery

So I have an anchor which looks like

<a href="http://something.com/something/" class="dropdown-toggle">something</a>

and I want to add

data-toggle="dropdown"

so that it ends up looking like

<a href="http://something.com/something/" class="dropdown-toggle" data-toggle="dropdown">something</a>

I tried

$(".dropdown-toggle").data("toggle", "dropdown");

But it isnt adding anything cheers

like image 269
Paul Browne Avatar asked Nov 13 '12 09:11

Paul Browne


People also ask

How to add data toggle attribute in javascript?

type = 'image'; button. onclick = function () { RemoveItem(this); }; button. style. marginLeft = '70px'; button.

How do you use data toggle?

Just add data-toggle="collapse" and a data-target to element to automatically assign control of a collapsible element. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element. If you'd like it to default open, add the additional class in.


1 Answers

You can use attr() jquery method to add the attribute.

Live Demo

$(".dropdown-toggle").attr("data-toggle", "dropdown");
like image 112
Adil Avatar answered Sep 20 '22 15:09

Adil