Corentin Branquet
Corentin Branquet

Reputation: 1576

Add specific attribute Jquery

I want to add an attr data-columns into <div id="grid">

Like this : <div id="grid" data-columns>

I try it but it does not work : $('#portfolio').attr("data-columns");

Thanks for your help !

Upvotes: 0

Views: 22

Answers (2)

Cruiser
Cruiser

Reputation: 1616

If you want to set an attribute, you need to give it a value:

$('#portfolio').attr("data-columns", "yourvalue");

http://api.jquery.com/attr/

Upvotes: 1

REDEVI_
REDEVI_

Reputation: 684

First you have to give some values to data-columns

<div id="grid" data-columns="some Value">

Then access it like

var x = $('#grid').attr("data-columns")

Upvotes: 0

Related Questions