Atlas91
Atlas91

Reputation: 5904

Javascript put attribute to a element

I'm using uikit and to open a dropdown i can set some attributes like:

data-uk-dropdown="{mode:'click',justify:'#my-id',}" 

this kind of way it's usable from html view in the input. Is it possible use the justify directly from javascript? I mean something like:

 $(document).on('focusin', '#my-id', function () {
        $('.uk-dropdown').justifly('#my-id');
    });

of course $('.uk-dropdown').justifly('#my-id'); it's not the correct way and it's not working.

Upvotes: 0

Views: 43

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82231

You need to use .attr() for setting the attribute value:

 $('.uk-dropdown').attr('justifly','#my-id');

for setting multiple attributes:

  $('.uk-dropdown').attr({'mode':'click','justify':'#my-id'});

Upvotes: 3

Related Questions