Like this :
I try it but it does not work : $('#portfolio').attr(" /> Like this :
I try it but it does not work : $('#portfolio').attr(" /> Like this :
I try it but it does not work : $('#portfolio').attr("/>

Add specific attribute Jquery

20 Views Asked by At

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 !

2

There are 2 best solutions below

0
REDEVI_ On

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")
0
Cruiser On

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

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

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